{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/4356","repository_url":"https://api.github.com/repos/realm/realm-cocoa","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4356/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4356/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4356/events","html_url":"https://github.com/realm/realm-cocoa/issues/4356","id":190918954,"number":4356,"title":"Default values for ignored properties don't work with query results","user":{"login":"stevenp","id":181589,"avatar_url":"https://avatars.githubusercontent.com/u/181589?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenp","html_url":"https://github.com/stevenp","followers_url":"https://api.github.com/users/stevenp/followers","following_url":"https://api.github.com/users/stevenp/following{/other_user}","gists_url":"https://api.github.com/users/stevenp/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenp/subscriptions","organizations_url":"https://api.github.com/users/stevenp/orgs","repos_url":"https://api.github.com/users/stevenp/repos","events_url":"https://api.github.com/users/stevenp/events{/privacy}","received_events_url":"https://api.github.com/users/stevenp/received_events","type":"User","site_admin":false},"labels":[{"id":3303146,"url":"https://api.github.com/repos/realm/realm-cocoa/labels/T:Help","name":"T:Help","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-22T06:35:07Z","updated_at":"2016-11-22T18:28:25Z","closed_at":null,"body":"## Goals\r\n\r\nI'm trying to have ignored properties on my models that have default values set.\r\n\r\n## Expected Results\r\n\r\nIf I create a property on a model that has a default value:\r\n```\r\n var testIgnoredProperty: String = \"x\"\r\n```\r\n...I want to be able to access the default value on both newly instantiated models and models retrieved from the database.\r\n\r\n## Actual Results\r\n\r\nWhen I create a new model instance with a default value set for an ignored property, I can access that property's value in a new instance, but when I retrieve the same model from the database, the default value is not set for the query result.\r\n\r\n## Steps to Reproduce\r\n\r\nThis is the test model class:\r\n\r\n```\r\nclass IgnoredPropertyTest: RLMObject {\r\n    \r\n    dynamic var id: String = \"\"\r\n    \r\n    dynamic var testIgnoredProperty: String = \"x\"\r\n    \r\n    override public class func primaryKey() -> String? {\r\n        return \"id\"\r\n    }\r\n    \r\n    override public class func ignoredProperties() -> [String]? {\r\n        return [\"testIgnoredProperty\"]\r\n    }\r\n}\r\n```\r\n\r\nThis is how I'm reproducing the behavior:\r\n```\r\nlet realm = RLMRealm.default()\r\nrealm.beginWriteTransaction()\r\n                        \r\nlet test = IgnoredPropertyTest()\r\ntest.id = \"1\"\r\nprint(test.testIgnoredProperty) // prints \"x\"\r\n\r\nrealm.addOrUpdate(test)\r\n                        \r\ntry realm.commitWriteTransaction()\r\n\r\nlet testFetched = IgnoredPropertyTest(forPrimaryKey: \"1\")!\r\nprint(testFetched.testIgnoredProperty) // prints \"\"\r\n```\r\n\r\nI would expect to see `x` printed twice, but in the case of the model retrieved from the database, the default value that's assigned to this property is gone. I've scoured the documentation and other issues to see if there's something obvious I'm missing here, but I can't figure it out. Is this the expected behavior? If so, is there a way to work around this?\r\n\r\n## Version of Realm and Tooling\r\n\r\nRealm version: 2.1.0\r\n\r\nXcode version: 8.1\r\n\r\niOS/OSX version: 10.1/10.12.2\r\n\r\nDependency manager + version: Cocoapods 1.2.0.beta.1\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments/262323880","html_url":"https://github.com/realm/realm-cocoa/issues/4356#issuecomment-262323880","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4356","id":262323880,"user":{"login":"stevenp","id":181589,"avatar_url":"https://avatars.githubusercontent.com/u/181589?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenp","html_url":"https://github.com/stevenp","followers_url":"https://api.github.com/users/stevenp/followers","following_url":"https://api.github.com/users/stevenp/following{/other_user}","gists_url":"https://api.github.com/users/stevenp/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenp/subscriptions","organizations_url":"https://api.github.com/users/stevenp/orgs","repos_url":"https://api.github.com/users/stevenp/repos","events_url":"https://api.github.com/users/stevenp/events{/privacy}","received_events_url":"https://api.github.com/users/stevenp/received_events","type":"User","site_admin":false},"created_at":"2016-11-22T18:28:25Z","updated_at":"2016-11-22T18:28:25Z","body":"This seems to occur for lazy properties as well. Everything I've read seems to indicate that ignored lazy properties are supposed to work as expected in Realm."}}
{"actor":{"display_login":"stevenp"}}