[{"content":"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 \u0026amp; .xib, the main project will not compile and will show following error.\n1 2 3 The document \u0026#34;Main.storyboard\u0026#34; requires XCode 8.0 or later. This version does not support documents saved in XCode 8 format. Open this document with XCode 8.0 or later. 1 The document \u0026#34;(null)\u0026#34; requires XCode 8.0 or later. 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.\nUsing XCode 8: If you have XCode 8 installed on your system, you can use this method to downgrade your storyboard files.\nOpen .storyboard/.xib file in XCode 8.0 On right side: Utility Area \u0026gt; File Inspecter \u0026gt; Interface Builder Document Choose \u0026lsquo;XCode 7.x\u0026rsquo; for \u0026lsquo;Opens in\u0026rsquo;s\u0026rsquo; value. The process is shown in GIF below: Using any text Editor 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.\nJust open your .storyboard/.xib file in a text editor of your choice and remove following line:\n1 \u0026lt;capability name=\u0026#34;Document saved in the Xcode 8 format\u0026#34; minToolVersion=\u0026#34;8.0\u0026#34;/\u0026gt; After removing this line you will be able to compile your project successfully.\nTo 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.\n","date":"2016-12-07T00:00:00Z","permalink":"/p/downgrade-ui-files-from-xcode-8-to-xcode-7/","title":"Downgrade UI Files from XCode 8 to XCode 7"},{"content":"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.\natomic (Default) 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\u0026rsquo;s say we have a property firstName which is atomic.\n1 2 3 - Thread A =\u0026gt; obj.firstName=@\u0026#34;A\u0026#34; - Thread B =\u0026gt; obj.firstName=@\u0026#34;B\u0026#34; - Thread C =\u0026gt; NSLog(\u0026#34;First Name: %@\u0026#34;,obj.firstName); It will ensure that the value of property remains consistent throughout the lifecycle. By default all properties are atomic.\nExample atomic property:\n1 2 3 @property (strong,atomic) NSString *firstName; OR @property (strong) NSString *firstName; Sample getter setter: This is how the methods of a property will look for an atomic property after\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 @synthesize firstName = _firstName; -(NSString *)firstName{ @synchronized (self) { return _firstName; } } -(void)setFirstName:(NSString *)firstName{ @synchronized (self) { if(_firstName != firstName){ [_firstName release]; _firstName = [firstName retain]; } } } Note: the Objective-C 2.0 specification, mentions that locks are used internally, but it doesn\u0026rsquo;t specify exactly how. What you see above, is roughly what an atomic getter/setter would look like, but it might not be accurate.\nPros: Ensures that user gets a valid value and not some garbage\nCons: Slow, as it has code to ensure read write safety\nnonatomic For non atomic properties multiple threads can access the properties simultaneously, so there is always a risk of inconsistency between values\nExample:\n1 @property (strong,nonatomic) NSString *firstName; Sample getter setter: This is how the methods of a properties will look for an atomic property\n1 2 3 4 5 6 7 8 9 10 @synthesize firstName = _firstName; -(NSString *)firstName{ return _firstName; } -(void)setFirstName:(NSString *)firstName{ if(_firstName != firstName){ [_firstName release]; _firstName = [firstName retain]; } } Pros: Fast as compared to atomic properties, as there is no extra code to control access of multiple threads\nCons: You are not guaranteed whether or not you will receive a valid value\nTODO [] Thread safe vs Read/Write Safe [] When is code created for properties i.e how \u0026amp; getter and setter code is created? [] When to use atomic vs non-atomic some solid rules? [] Detailed Pros \u0026amp; Cons [] Multi-threading on Single CPU vs Multiple threads Further Reading TMI #1: Objective-C Property Attributes Ry’s Objective-C Tutorial - Properties Apple\u0026rsquo;s Docs Gabriele Petronella\u0026rsquo;s Answer for Explicit getters/setters for @properties (MRC) Memory and thread-safe custom property methods ","date":"2016-10-25T00:00:00Z","image":"/p/atomic-vs-nonatomic-properties-in-objective-c/cover.png","permalink":"/p/atomic-vs-nonatomic-properties-in-objective-c/","title":"atomic vs nonatomic properties in Objective-C"},{"content":"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.\nNow 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.\n@synthesize 1 @synthesize propertyName = _propertyName; @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.\n@dynamic 1 @dynamic propertyName; 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 Dynamic Method Resolution.\nFurther Reading Dynamic Method Resolution @synthesize vs @dynamic, what are the differences? ","date":"2016-10-25T00:00:00Z","permalink":"/p/synthesize-vs-dynamic-in-objective-c/","title":"synthesize vs dynamic in Objective-C"},{"content":"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.\nDispatch Object lifecycle 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.\nFurther Readings Grand Central Dispatch (GCD) Reference ","date":"2016-03-30T00:00:00Z","permalink":"/p/dispatch-objects-in-gcd/","title":"Dispatch Objects in GCD"},{"content":"In a hurry to do things fast and meet monster deadlines, developers keep the book of best practices aside and start coding. The result can lead to unexpected behavior in your project along with highly unmanaged code. Start following best practices of coding, with time it will become a habit.\nEven the experienced programmers sometimes can\u0026rsquo;t foresee the issues embedded in their code.\nOCLint comes with a huge list of options which are way too lengthy anc can\u0026rsquo;t be covered in a single reading. In this tutorial we will cover best configurations suggested by OCLint documentation for XCode project.\nAbout OCLint OCLint is a static analyzer for C, C++ and objective c. The documentation to kick off your relationship with OCLint is huge and you will be jumping from one page to another in pursuit of something, something digestible. In this tutorial our goal is to Install, Integrate \u0026amp; View Analysis report of OCLint in XCode objective-c project.\nPrerequisite Homebrew xctool XCode OSX Installation 1. Homebrew, Easy and Recommended If homebrew is configured on your system, you can use homebrew tap for oclint.\n{% highlight text %} $ brew tap oclint/formulae $ brew install oclint {% endhighlight %}\nAnd can be simplified to\n{% highlight text %} $ brew install oclint/formulae/oclint {% endhighlight %}\nUse following commands to update to latest version\n{% highlight text %} $ brew update $ brew upgrade oclint {% endhighlight %}\n2. Download Ignore it if you have completed installation via Homebrew.\nGo to OCLint Releases on github and download latest oclint-{versionno-architecture-OS}.zip/.tar.zip. Extract the files.\n{% highlight text %} -oclint-x.y.z |\u0026ndash;LICENSE |\u0026ndash;bin (Contains OCLint commands, from here you can execute it) |\u0026ndash;lib (Contains clang static analyzer, reporters and rules library) {% endhighlight %}\nSet Path Once installation is complete you can set path in terminal\n{% highlight text %} OCLINT_HOME=/path/to/oclint-x.y.z export PATH=$OCLINT_HOME/bin:$PATH {% endhighlight %}\nVerify Installation Check whether installation is successful. If you see the output listed below, congratulations you did it.\n{% highlight text %} $ oclint oclint: Not enough positional command line arguments specified! Must specify at least 1 positional arguments: See: oclint -help {% endhighlight %}\nOCLint Commands 1. oclint OCLint comes with rich set of options which you can use with \u0026lsquo;oclint\u0026rsquo; command. In terminal type $ ocline --help to get detailed list of configurations.\n2. oclint-json-compilation-database It is great that OCLint provides us options to specify each file\u0026rsquo;s configurations. But in practical life our projects contains hundreds of files and it will give you a headache to do this manually. Here comes the solution oclint-json-compilation-database\nIntegration with XCode Add the following script to new run script.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 echo \u0026#34;Building ${TARGET_NAME}\u0026#34; maxPriority=15000 #Add OCLint bin directory to PATH export PATH=/usr/local/Cellar/oclint/0.10.2/bin:$PATH #Set Build path BUILD_PATH=${TARGET_TEMP_DIR} #Check whether OCLint exists or not hash oclint \u0026amp;\u0026gt; /dev/null if [ $? -eq 1 ]; then echo \u0026#34;OCLint not found, analyzing stopped\u0026#34; exit 1 else echo \u0026#34;OCLint is installed\u0026#34; fi #Navigate to build path directory cd ${BUILD_PATH} if [ ! -f compile_commands.json ]; then echo \u0026#34;compile_commands.json not found, possibly clean was performed\u0026#34;; else echo \u0026#34;Removing compile_commands.json\u0026#34; rm compile_commands.json fi # clean previous output if [ -f xcodebuild.log ]; then echo \u0026#34;Removing xcodebuild.log\u0026#34; rm xcodebuild.log fi cd ${SRCROOT} #Clean, Build and generate compile_commands.json project xctool -project DemoOCLintTargetInProject.xcodeproj \\ -configuration Debug -scheme DemoOCLintTargetInProject \\ -sdk iphonesimulator \\ -reporter json-compilation-database:${BUILD_PATH}/compile_commands.json clean build echo \u0026#34;Starting analyzing\u0026#34; cd ${BUILD_PATH} oclint-json-compilation-database -v -e Pods oclint_args \\ \u0026#34;-max-priority-1=$maxPriority -max-priority-2=$maxPriority \\ -max-priority-3=$maxPriority -rc LONG_LINE=500 \\ -rc LONG_VARIABLE_NAME=100 -disable-rule=UnusedMethodParameter\u0026#34; \\ | sed \u0026#39;s/\\(.*\\.\\m\\{1,2\\}:[0-9]*:[0-9]*:\\)/\\1 warning:/\u0026#39; Sample project DemoOCLintTargetInProject is the project we used for above demo and is published on git.\n","date":"2016-03-28T00:00:00Z","permalink":"/p/oclint-integration-in-xcode-with-xctool/","title":"OCLint integration in XCode with xctool"}]