{"id":13071,"date":"2015-12-11T14:05:24","date_gmt":"2015-12-11T19:05:24","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13071"},"modified":"2016-06-07T10:43:19","modified_gmt":"2016-06-07T14:43:19","slug":"double-core-data-accessors-by-omitting-nsmanaged","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/12\/11\/double-core-data-accessors-by-omitting-nsmanaged\/","title":{"rendered":"Double Core Data Accessors by Omitting @NSManaged"},"content":{"rendered":"<p><a href=\"http:\/\/martiancraft.com\/blog\/2015\/12\/nsmanaged\/\">Trevor Squires<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/martiancraft.com\/blog\/2015\/12\/nsmanaged\/\">\r\n<p>If our implementation is not exposed to Objective-C, then Core Data will not find it at runtime, which means that, yes, Core Data will dynamically generate the accessor implementation for us.<\/p>\r\n<p>[&#8230;]<\/p>\r\n<p>This is why I now consider Swift to be the most satisfying language for using Core Data. The fact that (more expressive) types can&rsquo;t be represented in Objective-C is a benefit, not a limitation.<\/p>\r\n<p>Swift <code>NSManagedObject<\/code> subclasses can provide Swift-only accessors which happily coexist with Core Data&rsquo;s dynamically-generated ones, and that feels like the best of both worlds.<\/p>\r\n<\/blockquote>\r\n\r\n<p>Update (2016-06-07): <a href=\"http:\/\/blog.mbcharbonneau.com\/2016\/06\/06\/four-small-random-and-unrelated-core-data-tips\/\">Marc Charbonneau<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/blog.mbcharbonneau.com\/2016\/06\/06\/four-small-random-and-unrelated-core-data-tips\/\"><p>When you declare an <code>@NSManaged<\/code> var in your managed object subclass, normally it can be an <code>Int<\/code>, <code>Bool<\/code>, or <code>Double<\/code>. But not for Core Data primitive accessors! Primitive accessors (not to be confused with primitive types, I\u2019m talking about methods that are a shorthand for <code>primitiveValueForKey: \u2026 <\/code>) <strong>must<\/strong> be declared as an <code>NSNumber<\/code>. You don\u2019t have to explicitly wrap your value in an <code>NSNumber<\/code>, you can still assign an <code>Int<\/code> or <code>Double<\/code> to your var and Swift will box it up for you. Not a big deal, but something to remember if you find your app crashing.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Trevor Squires: If our implementation is not exposed to Objective-C, then Core Data will not find it at runtime, which means that, yes, Core Data will dynamically generate the accessor implementation for us. [&#8230;] This is why I now consider Swift to be the most satisfying language for using Core Data. The fact that (more [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[109,31,30,54,71,901],"class_list":["post-13071","post","type-post","status-publish","format-standard","hentry","category-technology","tag-coredata","tag-ios","tag-mac","tag-objective-c","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=13071"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13071\/revisions"}],"predecessor-version":[{"id":14747,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13071\/revisions\/14747"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}