https://github.com/royalicing/swift-kick
Command line tool to ease Swift development
https://github.com/royalicing/swift-kick
Last synced: 9 months ago
JSON representation
Command line tool to ease Swift development
- Host: GitHub
- URL: https://github.com/royalicing/swift-kick
- Owner: RoyalIcing
- License: mit
- Created: 2016-04-08T07:34:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-20T12:28:01.000Z (about 10 years ago)
- Last Synced: 2024-04-25T02:03:59.922Z (about 2 years ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# swift-kick
Tool to ease Swift development.
## [Use online here](https://www.burntcaramel.com/swift-kick/)
## Command line tool instructions
### Enum Equality
1. Copy your Swift enum declaration with associated values.
2. `pbpaste | swift-kick enum:eq | pbcopy`
3. Paste.
### Enum [JSON parsing and serialization](https://github.com/BurntCaramel/JSON)
1. Copy your Swift enum declaration with associated values.
2. `pbpaste | swift-kick enum:json | pbcopy`
3. Paste.
## Example
```swift
// Example enum:
public enum ContentReference {
case localSHA256(sha256: String, contentType: ContentType)
case remote(url: NSURL, contentType: ContentType)
case collected1(host: String, account: String, id: String, contentType: ContentType)
}
```
```swift
// pbpaste | swift-kick enum:eq | pbcopy
public func == (lhs: ContentReference, rhs: ContentReference) {
switch (lhs, rhs) {
case let (.localSHA256(l), .localSHA256(r)):
return l.sha256 == r.sha256 && l.contentType == r.contentType
case let (.remote(l), .remote(r)):
return l.url == r.url && l.contentType == r.contentType
case let (.collected1(l), .collected1(r)):
return l.host == r.host && l.account == r.account && l.id == r.id && l.contentType == r.contentType
}
}
```
```swift
// pbpaste | swift-kick enum:json | pbcopy
extension ContentReference {
public enum Kind : String, KindType {
case localSHA256 = "localSHA256"
case remote = "remote"
case collected1 = "collected1"
}
public var kind: Kind {
switch self {
case .localSHA256: return .localSHA256
case .remote: return .remote
case .collected1: return .collected1
}
}
}
extension ContentReference : JSONObjectRepresentable {
public init(source: JSONObjectDecoder) throws {
let type: Kind = try source.decode("type")
switch type {
case .localSHA256:
self = try .localSHA256(
sha256: source.decode("sha256"),
contentType: source.decode("contentType")
)
case .remote:
self = try .remote(
url: source.decodeURL("url"),
contentType: source.decode("contentType")
)
case .collected1:
self = try .collected1(
host: source.decode("host"),
account: source.decode("account"),
id: source.decode("id"),
contentType: source.decode("contentType")
)
}
}
public func toJSON() -> JSON {
switch self {
case let .localSHA256(sha256, contentType):
return .ObjectValue([
"type": Kind.localSHA256.toJSON(),
"sha256": sha256.toJSON(),
"contentType": contentType.toJSON()
])
case let .remote(url, contentType):
return .ObjectValue([
"type": Kind.remote.toJSON(),
"url": url.toJSON(),
"contentType": contentType.toJSON()
])
case let .collected1(host, account, id, contentType):
return .ObjectValue([
"type": Kind.collected1.toJSON(),
"host": host.toJSON(),
"account": account.toJSON(),
"id": id.toJSON(),
"contentType": contentType.toJSON()
])
}
}
}
```
## Installation
Requires [node.js](https://nodejs.org/en/download/package-manager/)
```
npm install -g swift-kick
```