{"action":"created","issue":{"url":"https://api.github.com/repos/ovenbits/ModelRocket/issues/12","labels_url":"https://api.github.com/repos/ovenbits/ModelRocket/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/ovenbits/ModelRocket/issues/12/comments","events_url":"https://api.github.com/repos/ovenbits/ModelRocket/issues/12/events","html_url":"https://github.com/ovenbits/ModelRocket/issues/12","id":120972335,"number":12,"title":"Unexpected type required property","user":{"login":"pimnijman","id":6617033,"avatar_url":"https://avatars.githubusercontent.com/u/6617033?v=3","gravatar_id":"","url":"https://api.github.com/users/pimnijman","html_url":"https://github.com/pimnijman","followers_url":"https://api.github.com/users/pimnijman/followers","following_url":"https://api.github.com/users/pimnijman/following{/other_user}","gists_url":"https://api.github.com/users/pimnijman/gists{/gist_id}","starred_url":"https://api.github.com/users/pimnijman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pimnijman/subscriptions","organizations_url":"https://api.github.com/users/pimnijman/orgs","repos_url":"https://api.github.com/users/pimnijman/repos","events_url":"https://api.github.com/users/pimnijman/events{/privacy}","received_events_url":"https://api.github.com/users/pimnijman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-08T09:52:18Z","updated_at":"2015-12-09T04:33:37Z","closed_at":"2015-12-09T04:33:37Z","body":"*JSON*\r\n```\r\n{ \"model\": 15 } // This should be a string, but due to a server side bug, this is now an int.\r\n```\r\n\r\n*Swift*\r\n```swift\r\nclass Vehicle: Model {\r\n    let model = Property<String>(key: \"model\", required: true)\r\n}\r\n```\r\n\r\n*Expected behavior*\r\nSince \"model\" is not of type String, but of type Int, I expect the the model property to become nil and since model is required I expect the vehicle object not to be initialized.\r\n\r\n*Behaviour*\r\nThe vehicle object is initialized while the model property is nil.\r\nThis causes a crash when I unwrap the model property: `print(\"Vehicle make: \\(vehicle.make.value!)\")`\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ovenbits/ModelRocket/issues/comments/163106709","html_url":"https://github.com/ovenbits/ModelRocket/issues/12#issuecomment-163106709","issue_url":"https://api.github.com/repos/ovenbits/ModelRocket/issues/12","id":163106709,"user":{"login":"jlandon","id":4239255,"avatar_url":"https://avatars.githubusercontent.com/u/4239255?v=3","gravatar_id":"","url":"https://api.github.com/users/jlandon","html_url":"https://github.com/jlandon","followers_url":"https://api.github.com/users/jlandon/followers","following_url":"https://api.github.com/users/jlandon/following{/other_user}","gists_url":"https://api.github.com/users/jlandon/gists{/gist_id}","starred_url":"https://api.github.com/users/jlandon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlandon/subscriptions","organizations_url":"https://api.github.com/users/jlandon/orgs","repos_url":"https://api.github.com/users/jlandon/repos","events_url":"https://api.github.com/users/jlandon/events{/privacy}","received_events_url":"https://api.github.com/users/jlandon/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T04:33:36Z","updated_at":"2015-12-09T04:33:36Z","body":"Hey @pimnijman,\r\n\r\nTo fully utilize the required properties, you should use the `strictJSON:` initializer. See: https://github.com/ovenbits/ModelRocket#initializing-and-using-a-custom-object\r\n\r\nThe `json:` initializer does not account for required properties, so that initializer returns a non-optional model object, and the properties are not guaranteed to have non-nil values. What you're attempting to do works, if you use the `strictJSON:` initializer like this:\r\n\r\n```swift\r\nif let vehicle = Vehicle(strictJSON: <json>) {\r\n   print(\"Vehicle make: \\(vehicle.make.value!)\")\r\n}\r\n```"}}