SwiftyModel

Settings

Every option in the settings column applies to the Swift result straight away, and is restored the next time you open SwiftyModel.

Layout

SettingValuesDefaultEffect
LayoutStacked / Side by SideStackedHow the JSON and Swift editors are arranged. Side by side widens the window to fit both.

Code Settings

SettingValuesDefaultEffect
Indent2 Spaces / 4 Spaces4 SpacesSpaces per level of indentation.
Model NameAny nameNewModelName 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 Typestruct / classstructWhether to generate structures or classes. Nested types use the same kind.
Model Access Leveldefault / public / internal / privatedefaultAccess modifier written before each type. default writes none, which Swift treats as internal.
Property Access Leveldefault / public / internal / privatedefaultAccess modifier written before each property.
Property is VariableOn / OffOffDeclares properties with var instead of let.
CodableOn / OffOffAdds Codable conformance and a CodingKeys enum that maps each property back to its JSON key. init(json:) is still generated.
InitializerOn / OffOffAdds a memberwise initializer that takes every property as a parameter.
Property Naming Snake to CamelOn / OffOnTurns 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 KeywordsPrefix / Suffix, plus some textPrefix, keyWhen 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" }.

Swift
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.