<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Ios on Nabeel's - iOS Developer Blog</title><link>https://nabeelarif.github.io/tags/ios/</link><description>Recent content in Ios on Nabeel's - iOS Developer Blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 07 Dec 2016 00:00:00 +0000</lastBuildDate><atom:link href="https://nabeelarif.github.io/tags/ios/index.xml" rel="self" type="application/rss+xml"/><item><title>Downgrade UI Files from XCode 8 to XCode 7</title><link>https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/</link><pubDate>Wed, 07 Dec 2016 00:00:00 +0000</pubDate><guid>https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/</guid><description>&lt;p&gt;In one of my recent project I developed a module in XCode 8 as I had upgraded to it. Later I came to know that our team is currently working on XCode 7. So if we integrate XCode 8 UI files i.e .storyboard &amp;amp; .xib, the main project will not compile and will show following error.&lt;/p&gt;
&lt;p&gt;&lt;img alt="UI Files of XCode 8 opened in XCode 7" class="gallery-image" data-flex-basis="647px" data-flex-grow="269" height="712" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project.png" srcset="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project_hu_81ec24db7b36c718.png 800w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project_hu_920df4157212a46c.png 1600w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project.png 1922w" width="1922"&gt;
&lt;img alt="UI Files of XCode 8 opened in XCode 7 (2)" class="gallery-image" data-flex-basis="674px" data-flex-grow="280" height="682" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project2.png" srcset="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project2_hu_798e35bfad1a40d8.png 800w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project2_hu_6957aaaa6ab5b26.png 1600w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ErrorOnXCode7ForXCode8Project2.png 1916w" width="1916"&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;The document &amp;#34;Main.storyboard&amp;#34; requires XCode 8.0 or later.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;This version does not support documents saved in XCode 8 format. Open this document with XCode 8.0 or later.
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;The document &amp;#34;(null)&amp;#34; requires XCode 8.0 or later.
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Although it is strongly recommended to upgrade your XCode as soon as some stable version arrives, there can come certain situations where you have to downgrade it. If you are a developer like me who is trying to downgrade his project to support XCode 7 here are two simple ways.&lt;/p&gt;
&lt;h1 id="using-xcode-8"&gt;Using XCode 8:
&lt;/h1&gt;&lt;p&gt;If you have XCode 8 installed on your system, you can use this method to downgrade your storyboard files.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Open .storyboard/.xib file in XCode 8.0&lt;/li&gt;
&lt;li&gt;On right side: Utility Area &amp;gt; File Inspecter &amp;gt; Interface Builder Document&lt;/li&gt;
&lt;li&gt;Choose &amp;lsquo;XCode 7.x&amp;rsquo; for &amp;lsquo;Opens in&amp;rsquo;s&amp;rsquo; value. The process is shown in GIF below:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Downgrade to XCode 7 using XCode 8" class="gallery-image" data-flex-basis="338px" data-flex-grow="141" height="340" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/DowngradeToXCode7.gif" width="480"&gt;&lt;/p&gt;
&lt;h1 id="using-any-text-editor"&gt;Using any text Editor
&lt;/h1&gt;&lt;p&gt;If you do not have access to XCode 8 at the moment you can use any of the text editors available to downgrade to XCode 7. So that you have no more build errors.&lt;/p&gt;
&lt;p&gt;Just open your .storyboard/.xib file in a text editor of your choice and remove following line:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;lt;capability name=&amp;#34;Document saved in the Xcode 8 format&amp;#34; minToolVersion=&amp;#34;8.0&amp;#34;/&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;img alt="Downgrade to XCode 7 using text editor" class="gallery-image" data-flex-basis="461px" data-flex-grow="192" height="920" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ManuallyDowngradeToXCode7.png" srcset="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ManuallyDowngradeToXCode7_hu_ca4c46121aa4ca69.png 800w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ManuallyDowngradeToXCode7_hu_4cc0582373b7bb4e.png 1600w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/ManuallyDowngradeToXCode7.png 1770w" width="1770"&gt;&lt;/p&gt;
&lt;p&gt;After removing this line you will be able to compile your project successfully.&lt;/p&gt;
&lt;p&gt;To understand why we removed above line you can explore the changes once a UI file is saved in Xcode 8 format. If you will open .storyboard or .xib file on XCode 8 first time. It will show you a dialog as shown below to make these files compatible with XCode 8 document format.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Dialog to make storyboard file XCode8 compatible" class="gallery-image" data-flex-basis="588px" data-flex-grow="245" height="784" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/StoryboardUpgradedToXCode8.png" srcset="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/StoryboardUpgradedToXCode8_hu_f8918747d608ad3d.png 800w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/StoryboardUpgradedToXCode8_hu_2b793e25052b4dad.png 1600w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/StoryboardUpgradedToXCode8.png 1922w" width="1922"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="Git Diff of storyboard file after upgrade to XCode 8" class="gallery-image" data-flex-basis="1183px" data-flex-grow="493" height="288" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/GitDiffAfterUpgradeToXCode8.png" srcset="https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/GitDiffAfterUpgradeToXCode8_hu_49e75aa250f7f56a.png 800w, https://nabeelarif.github.io/p/downgrade-ui-files-from-xcode-8-to-xcode-7/GitDiffAfterUpgradeToXCode8.png 1420w" width="1420"&gt;&lt;/p&gt;</description></item><item><title>atomic vs nonatomic properties in Objective-C</title><link>https://nabeelarif.github.io/p/atomic-vs-nonatomic-properties-in-objective-c/</link><pubDate>Tue, 25 Oct 2016 00:00:00 +0000</pubDate><guid>https://nabeelarif.github.io/p/atomic-vs-nonatomic-properties-in-objective-c/</guid><description>&lt;img src="https://nabeelarif.github.io/" alt="Featured image of post atomic vs nonatomic properties in Objective-C" /&gt;&lt;p&gt;The difference between atomic and non atomic properties remained a favourite question for interviewers. Today we will analyse these keywords in detail. These keyword define the characteristics of how these properties will behave once they will be accessed from multiple threads simultaneously.&lt;/p&gt;
&lt;h1 id="atomic-default"&gt;atomic (Default)
&lt;/h1&gt;&lt;p&gt;As the word explains itself, a single thread will be able to access the property at a given time. To explain more, only one thread will be able to access getter/setter of a property. Other threads have to wait until first thread releases get/set method. Let&amp;rsquo;s say we have a property firstName which is atomic.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;- Thread &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&amp;gt; obj.firstName&lt;span class="o"&gt;=&lt;/span&gt;@&lt;span class="s2"&gt;&amp;#34;A&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;- Thread &lt;span class="nv"&gt;B&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&amp;gt; obj.firstName&lt;span class="o"&gt;=&lt;/span&gt;@&lt;span class="s2"&gt;&amp;#34;B&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;- Thread &lt;span class="nv"&gt;C&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&amp;gt; NSLog&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;First Name: %@&amp;#34;&lt;/span&gt;,obj.firstName&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;It will ensure that the value of property remains consistent throughout the lifecycle. By default all properties are atomic.&lt;/p&gt;
&lt;p&gt;Example atomic property:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@property &lt;span class="o"&gt;(&lt;/span&gt;strong,atomic&lt;span class="o"&gt;)&lt;/span&gt; NSString *firstName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;OR
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@property &lt;span class="o"&gt;(&lt;/span&gt;strong&lt;span class="o"&gt;)&lt;/span&gt; NSString *firstName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Sample getter setter:
This is how the methods of a property will look for an atomic property after&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@synthesize &lt;span class="nv"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; _firstName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-&lt;span class="o"&gt;(&lt;/span&gt;NSString *&lt;span class="o"&gt;)&lt;/span&gt;firstName&lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; @synchronized &lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; _firstName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-&lt;span class="o"&gt;(&lt;/span&gt;void&lt;span class="o"&gt;)&lt;/span&gt;setFirstName:&lt;span class="o"&gt;(&lt;/span&gt;NSString *&lt;span class="o"&gt;)&lt;/span&gt;firstName&lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; @synchronized &lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;_firstName !&lt;span class="o"&gt;=&lt;/span&gt; firstName&lt;span class="o"&gt;){&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;[&lt;/span&gt;_firstName release&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;_firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;firstName retain&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Note: the Objective-C 2.0 specification, mentions that locks are used internally, but it doesn&amp;rsquo;t specify exactly how. What you see above, is roughly what an atomic getter/setter would look like, but it might not be accurate.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt; Ensures that user gets a valid value and not some garbage&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt; Slow, as it has code to ensure read write safety&lt;/p&gt;
&lt;h1 id="nonatomic"&gt;nonatomic
&lt;/h1&gt;&lt;p&gt;For non atomic properties multiple threads can access the properties simultaneously, so there is always a risk of inconsistency between values&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@property &lt;span class="o"&gt;(&lt;/span&gt;strong,nonatomic&lt;span class="o"&gt;)&lt;/span&gt; NSString *firstName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Sample getter setter:
This is how the methods of a properties will look for an atomic property&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@synthesize &lt;span class="nv"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; _firstName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-&lt;span class="o"&gt;(&lt;/span&gt;NSString *&lt;span class="o"&gt;)&lt;/span&gt;firstName&lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; _firstName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-&lt;span class="o"&gt;(&lt;/span&gt;void&lt;span class="o"&gt;)&lt;/span&gt;setFirstName:&lt;span class="o"&gt;(&lt;/span&gt;NSString *&lt;span class="o"&gt;)&lt;/span&gt;firstName&lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;_firstName !&lt;span class="o"&gt;=&lt;/span&gt; firstName&lt;span class="o"&gt;){&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;[&lt;/span&gt;_firstName release&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;_firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;firstName retain&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt; Fast as compared to atomic properties, as there is no extra code to control access of multiple threads&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt; You are not guaranteed whether or not you will receive a valid value&lt;/p&gt;
&lt;h1 id="todo"&gt;TODO
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;[] Thread safe vs Read/Write Safe&lt;/li&gt;
&lt;li&gt;[] When is code created for properties i.e how &amp;amp; getter and setter code is created?&lt;/li&gt;
&lt;li&gt;[] When to use atomic vs non-atomic some solid rules?&lt;/li&gt;
&lt;li&gt;[] Detailed Pros &amp;amp; Cons&lt;/li&gt;
&lt;li&gt;[] Multi-threading on Single CPU vs Multiple threads&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="further-reading"&gt;Further Reading
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://realm.io/news/tmi-objective-c-property-attributes/" target="_blank" rel="noopener"
 &gt;TMI #1: Objective-C Property Attributes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="http://rypress.com/tutorials/objective-c/properties" target="_blank" rel="noopener"
 &gt;Ry’s Objective-C Tutorial - Properties&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html" target="_blank" rel="noopener"
 &gt;Apple&amp;rsquo;s Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="http://stackoverflow.com/a/21802205/800848" target="_blank" rel="noopener"
 &gt;Gabriele Petronella&amp;rsquo;s Answer for Explicit getters/setters for @properties (MRC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="http://www.cocoawithlove.com/2009/10/memory-and-thread-safe-custom-property.html" target="_blank" rel="noopener"
 &gt;Memory and thread-safe custom property methods&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>synthesize vs dynamic in Objective-C</title><link>https://nabeelarif.github.io/p/synthesize-vs-dynamic-in-objective-c/</link><pubDate>Tue, 25 Oct 2016 00:00:00 +0000</pubDate><guid>https://nabeelarif.github.io/p/synthesize-vs-dynamic-in-objective-c/</guid><description>&lt;p&gt;At the core of Object Orientation you should not access data directly, instead you should use accessor methods to get or set the data. In Objective-C @property directive is a simplified way in which developers can tell the compiler about the behavior required for the accessor methods, which is simple and brief.&lt;/p&gt;
&lt;p&gt;Now the question arise, where are the accessor methods? This leads us to the key words which are our topic today i.e @synthesize and @dynamic.&lt;/p&gt;
&lt;h1 id="synthesize"&gt;@synthesize
&lt;/h1&gt;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@synthesize &lt;span class="nv"&gt;propertyName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; _propertyName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;@synthesize tells the compiler to take care of the accessor methods creation i.e it will generate the methods based on property description. It will also generate an instance variable to be used which you can specify as above, as a convention it starts with _(underscore)+propertyName.&lt;/p&gt;
&lt;h1 id="dynamic"&gt;@dynamic
&lt;/h1&gt;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@dynamic propertyName&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;mentioning @dynamic with a propertyName tells the compiler not to create accessor methods because user will provide the implementation dynamically in future. Apple allows its developers to provide method implementation at runtime using &lt;a class="link" href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtDynamicResolution.html" target="_blank" rel="noopener"
 &gt;Dynamic Method Resolution&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id="further-reading"&gt;Further Reading
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtDynamicResolution.html" target="_blank" rel="noopener"
 &gt;Dynamic Method Resolution&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="http://stackoverflow.com/questions/1160498/synthesize-vs-dynamic-what-are-the-differences" target="_blank" rel="noopener"
 &gt;@synthesize vs @dynamic, what are the differences?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Dispatch Objects in GCD</title><link>https://nabeelarif.github.io/p/dispatch-objects-in-gcd/</link><pubDate>Wed, 30 Mar 2016 00:00:00 +0000</pubDate><guid>https://nabeelarif.github.io/p/dispatch-objects-in-gcd/</guid><description>&lt;p&gt;Grand Central Dispatch (GCD) is a technology by Apple to manage multiple cores of hardware at system level. As GCD is built at lower level and closer to unix system, it can manage muliple cores and developer do not have to worry about it. GCD provides a set of APIs which a developer can use to submit code blocks (dispatch objects) to it, after that GCD can do its magic.&lt;/p&gt;
&lt;h1 id="dispatch-object-lifecycle"&gt;Dispatch Object lifecycle
&lt;/h1&gt;&lt;p&gt;When compiled with Objective-C compiler dispatch objects behave like normal Objective-C objects. They are reatained and then released at the end of their lifecycle automatically in ARC.&lt;/p&gt;
&lt;h1 id="further-readings"&gt;Further Readings
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/" target="_blank" rel="noopener"
 &gt;Grand Central Dispatch (GCD) Reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>