{"id":1736,"date":"2013-09-26T08:41:16","date_gmt":"2013-09-26T15:41:16","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1736"},"modified":"2013-09-26T08:41:16","modified_gmt":"2013-09-26T15:41:16","slug":"synthesize-by-default","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1736","title":{"rendered":"Synthesize By Default"},"content":{"rendered":"<p>In 2012 Apple introduced Synthesize By Default in Xcode. You no longer have to synthesize instance variables. Just declare them as you normally would in the .h file and the compiler will automatically synthesize them for you. I learned how to use Xcode before the transition so I just learned about this by accident. If you haven\u2019t done so, watch these two videos from WWDC 2012: Session 405 &#8211; Modern Objective-C and Session 413 &#8211; Migrating to Modern Objective-C.<\/p>\n<p>Synthesize By Default is not available for NSManagedObjects so if your header file contains something like this:<br \/>\n<pre><code class=\"preserve-code-formatting\">\n@interface WordList : NSManagedObject\n<\/code><\/pre><br \/>\nYou\u2019ll have to synthesize.<\/p>\n<p>You can still manually create setters or getters and the compiler will automatically create the other accessor.<\/p>\n<p>One caveat. I stopped supporting iOS4.3 and still have code that is compatible with iOS4. Since  doesn&#8217;t have the weak indicator, you need to change assign to weak, then delete the &#8216;__unsafe_unretained id <PracticeSightWordsDelegate> delegate;&#8217; line. Then you can delete the @synthesize. If you still want to support iOS4, you\u2019ll need to synthesize these variables.<\/p>\n<p><b>Before<\/b><br \/>\n<pre><code class=\"preserve-code-formatting\">\n@implementation PracticeSightWords\n@synthesize delegate = _delegate;\n<\/code><\/pre><\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n@interface PracticeSightWords : UIViewController {\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;__unsafe_unretained id &lt;PracticeSightWordsDelegate&gt; delegate;\n}\n\n@property (nonatomic, assign) id &lt;PracticeSightWordsDelegate&gt; delegate;\n<\/code><\/pre><\/p>\n<p><b>After<\/b><br \/>\n<pre><code class=\"preserve-code-formatting\">\n@interface PracticeSightWords : UIViewController \n\n@property (nonatomic, weak) id &lt;PracticeSightWordsDelegate&gt; delegate;\n<\/code><\/pre><\/p>\n<p>I have my compiler warnings <a href=\"http:\/\/www.wellgolly.com\/?p=1590\">Turned up to 11<\/a> so I needed to turn off the warnings for \u201cImplicit Synthesized Properties\u201d in the &#8216;Warnings-Objective C&#8217; section of the build settings.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In 2012 Apple introduced Synthesize By Default in Xcode. You no longer have to synthesize instance variables. Just declare them as you normally would in the .h file and the compiler will automatically synthesize them for you. I learned how to use Xcode before the transition so I just learned about this by accident. If &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1736\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Synthesize By Default<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1736","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1736"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1736\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}