Settings
Every option in the settings column applies to the Swift result straight away, and is restored the next time you open SwiftyModel.
Layout
| Setting | Values | Default | Effect |
|---|---|---|---|
| Layout | Stacked / Side by Side | Stacked | How the JSON and Swift editors are arranged. Side by side widens the window to fit both. |
Code Settings
| Setting | Values | Default | Effect |
|---|---|---|---|
| Indent | 2 Spaces / 4 Spaces | 4 Spaces | Spaces per level of indentation. |
| Model Name | Any name | NewModel | Name of the top-level type. Spaces and other characters that Swift does not allow in names are tidied into a valid identifier. A name that clashes with a reserved name such as class or String gets Model appended. |
| Model Type | struct / class | struct | Whether to generate structures or classes. Nested types use the same kind. |
| Model Access Level | default / public / internal / private | default | Access modifier written before each type. default writes none, which Swift treats as internal. |
| Property Access Level | default / public / internal / private | default | Access modifier written before each property. |
| Property is Variable | On / Off | Off | Declares properties with var instead of let. |
| Codable | On / Off | Off | Adds Codable conformance and a CodingKeys enum that maps each property back to its JSON key. init(json:) is still generated. |
| Initializer | On / Off | Off | Adds a memberwise initializer that takes every property as a parameter. |
| Property Naming Snake to Camel | On / Off | On | Turns keys such as user_name into userName. When off, property names use lowercase snake_case, so a key such as userName becomes user_name. |
| Naming Avoid Keywords | Prefix / Suffix, plus some text | Prefix, key | When a property name is a Swift keyword, adds this text to it. For example, self becomes keySelf with a prefix or selfKey with a suffix. |
Keys starting with a digit, such as 2nd_place, cannot be Swift identifiers as they are, so they always use the prefix, even when Suffix is selected.
An example
This result uses Model Type class, public for both access levels, Property is Variable and Initializer turned on, the model name Tag, and the input { "id": 1, "name": "A" }.
import Foundation
import SwiftyJSON
public class Tag {
public var id: Int
public var name: String
init(id: Int, name: String) {
self.id = id
self.name = name
}
init(json: JSON) {
id = json["id"].intValue
name = json["name"].stringValue
}
}The memberwise initializer and init(json:) have no access modifier. To call them from another module, add public to them yourself.