SwiftyModel

Troubleshooting

Find the message you see, or what is happening, and how to fix it.

Messages

“JSON syntax is invalid or incomplete. Complete the object or array.”

SwiftyModel accepts standard JSON only. The message is followed by the line and column of the problem. Common causes:

  • a comma after the last item, as in [1, 2,];
  • single quotes, or keys without double quotes, as in {name: 'Ada'};
  • // or /* */ comments;
  • extra text copied along with the JSON from a log, or only part of it copied.

The result updates as soon as the JSON is fixed. Until then the previous result stays visible but cannot be copied or shared, so stale code does not end up in your project.

“Generating a model requires a top-level object or array.”

The JSON is valid, but it is a single string, number, Boolean or null. Put it inside an object, such as { "value": 42 }.

“Not text”

You clicked Paste, but the clipboard holds no text, for example an image or a file. Copy the JSON as text and try again, or press ⌘V in the editor.

“Could not copy the model. Try again.”

Writing to the clipboard failed, which is usually temporary. Click Copy again. If it keeps happening, click in the Swift result, select all with ⌘A and copy with ⌘C.

Using the code in Xcode

No such module 'SwiftyJSON'

Generated code depends on SwiftyJSON, even with Codable on. Add the SwiftyJSON package as described in Getting started.

Missing keys come back as empty strings or 0

Generated properties are not optional. When reading with init(json:), a missing key or a value of the wrong type gets SwiftyJSON's default: an empty string, 0, false or an empty array. If you need to tell “no value” apart, change those properties to optionals yourself. With JSONDecoder, a missing key throws an error instead.

A property has an unexpected type

Types are inferred from your sample JSON. If the sample happens to contain a whole number, you get Int; if real data can be a decimal, put a decimal in the sample or edit the type afterwards. Arrays with values of different types become [Any] or [JSON]; see How code is generated.

The window

The settings column is gone

It is hidden. Click the sidebar button on the right of the toolbar, or press ⌃⌘S.

There is no window after closing one

SwiftyModel keeps running after you close its last window. Click its icon in the Dock, or choose File > New Window (⌘N).

Still stuck? Contact the developer from the Support page.