{"id":23538,"date":"2018-11-29T16:43:28","date_gmt":"2018-11-29T21:43:28","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=23538"},"modified":"2019-01-18T10:28:53","modified_gmt":"2019-01-18T15:28:53","slug":"effective-core-data-with-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/11\/29\/effective-core-data-with-swift\/","title":{"rendered":"Effective Core Data With Swift"},"content":{"rendered":"<p><a href=\"https:\/\/www.youtube.com\/watch?v=w7tFF7IfKVk\">Tom Harrington<\/a> (<a href=\"https:\/\/github.com\/tryswift\/talks\/blob\/master\/Effective%20Core%20Data%20with%20Swift.pdf\">PDF<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.youtube.com\/watch?v=w7tFF7IfKVk\">\n<p>Core Data brings a lot of power to an app and continues to evolve, but it can have rough spots when you&rsquo;re working in Swift. What if you want to save an enum pr a struct? Does it help if your data is Codable? What&rsquo;s the best way to create Swift-friendly model classes? This session will cover techniques and gotchas for integrating Core Data with your Swift code<\/p>\n<\/blockquote>\n\n<p>It&rsquo;s a bit of a mystery to me why Xcode&rsquo;s generated code for Core Data <a href=\"https:\/\/twitter.com\/rentzsch\/status\/743866055081111552\">continues<\/a> to be so unhelpful compared with <a href=\"https:\/\/github.com\/rentzsch\/mogenerator\">mogenerator<\/a>.<\/p>\n\n<p>Another option for his <code>enum<\/code> example is that, if you have the ability to change the <code>enum<\/code>&rsquo;s definition, you can make it <code>@objc enum<\/code>. Then you can just declare the <code>@NSManaged<\/code> property using the proper type instead of having to write a getter and setter. The disadvantage of this, though, is that an <code>@objc enum<\/code> only shows up <a href=\"https:\/\/stackoverflow.com\/questions\/42513337\/why-does-an-objc-enum-have-a-different-description-than-a-pure-swift-enum\">as the type name<\/a> if you ask for its <code>description<\/code>. To see the actual case, e.g. when logging, you would need to implement <code>CustomStringConvertible<\/code>.<\/p>\n\n<p>There are also a lot more videos from the <a href=\"https:\/\/www.youtube.com\/channel\/UCuPue-GLK4nVX8klxQITIOw\">try! Swift Conference<\/a>.<\/p>\n\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2015\/03\/17\/using-core-data-with-swift\/\">Using Core Data With Swift<\/a>, <a href=\"https:\/\/mjtsai.com\/blog\/2015\/12\/02\/generating-core-data-swift\/\">Generating Core Data Swift<\/a>, <a href=\"https:\/\/mjtsai.com\/blog\/2016\/06\/24\/modern-core-data-with-swift\/\">Modern Core Data With Swift<\/a>, <a href=\"https:\/\/mjtsai.com\/blog\/2013\/04\/17\/momdec-core-data-model-decompiler\/\">momdec: Core Data Model Decompiler<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Tom Harrington (PDF): Core Data brings a lot of power to an app and continues to evolve, but it can have rough spots when you&rsquo;re working in Swift. What if you want to save an enum pr a struct? Does it help if your data is Codable? What&rsquo;s the best way to create Swift-friendly model [&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":"2018-11-29T21:43:31Z","apple_news_api_id":"a98bb41a-76d8-48ec-91dd-8677dc0bf6ea","apple_news_api_modified_at":"2019-01-18T15:29:00Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AqYu0GnbYSOyR3YZ33Av26g","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":[4],"tags":[888,738,109,31,1610,30,1609,1004,71,1774,901,226],"class_list":["post-23538","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-code-generation","tag-conference","tag-coredata","tag-ios","tag-ios-12","tag-mac","tag-macos-10-14","tag-mogenerator","tag-programming","tag-swift-codable","tag-swift-programming-language","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23538","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=23538"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23538\/revisions"}],"predecessor-version":[{"id":23539,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23538\/revisions\/23539"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=23538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=23538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=23538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}