https://github.com/nicholasbellucci/finch
An Xcode source extension for quickly creating Codable models from JSON.
https://github.com/nicholasbellucci/finch
Last synced: 10 days ago
JSON representation
An Xcode source extension for quickly creating Codable models from JSON.
- Host: GitHub
- URL: https://github.com/nicholasbellucci/finch
- Owner: NicholasBellucci
- License: mit
- Created: 2020-12-09T04:07:47.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2021-02-11T15:55:17.000Z (over 4 years ago)
- Last Synced: 2025-02-17T03:44:30.002Z (3 months ago)
- Language: Swift
- Size: 655 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Finch
A lightweight Xcode source extension that assists in transforming JSON into Codable Swift models.
Finch will take care of everything. This includes creating a top level model, children models, and declaring the proper types and coding keys. Any unknown types will be generated as placeholder `Any` types.## Roadmap
- [x] Support OSX 10.15
- [ ] Add customization settings in the desktop app
- [ ] Add option for custom encode/decode initializers
- [ ] Add Objective-C language option## Usage
Finch works with your clipboard to create the necessary models. All you need to do is copy some JSON, return to Xcode, and choose `Editor` > `Finch` > `Convert JSON to Codables` from the menu bar. A keyboard shortcut for this command can be set in Xcode `Preferences` > `Key Bindings` > `Convert JSON to Codables`## Example
### JSON
```json
[
{
"_id": "5973782bdb9a930533b05cb2",
"balance": "$1,446.35",
"age": 32,
"name": "Logan Keller",
"email": "[email protected]",
"phone": "+1 (952) 533-2258",
"friends": [
{
"id": 0,
"name": "Colon Salazar"
},
{
"id": 1,
"name": "French Mcneil"
}
]
}
]
```
### Swift
```swift
public struct <#ModelName#>: Codable {
public enum CodingKeys: String, CodingKey, CaseIterable {
case id = "_id"
case age
case balance
case email
case friends
case name
case phone
}public var id: String
public var age: Double
public var balance: String
public var email: URL
public var friends: [Friend]
public var name: String
public var phone: Stringpublic init(id: String, age: Double, balance: String, email: URL, friends: [Friend], name: String, phone: String) {
self.id = id
self.age = age
self.balance = balance
self.email = email
self.friends = friends
self.name = name
self.phone = phone
}
}public struct Friend: Codable {
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case name
}public var id: Double
public var name: Stringpublic init(id: Double, name: String) {
self.id = id
self.name = name
}
}
```## License
Finch is, and always will be, MIT licensed. See [LICENSE](LICENSE) for details.