Saturday, January 28, 2012

ARC Part 4: Simple ARC project Demo

In todays post we will learn on how to create a small arc demo from the scratch.


Step 1: Open Xcode and create an empty application and give it an appropriate name (for this demo i will go with the login demo), 




When you hit the next button the xcode will ask you for the name of your project after entering the name of your project make sure that you select the use Automatic reference counting check box as given in the below image




Step 2: Create a view which looks like the one given below with the help of coding or via interface builder as per your convenience


Step 3: Now create the IBOutlets and IBAction for the view that you have created since its a view with a login button and a clear button then in this case their will be two functions make sure that you give your naming conventions properly, given below is the code for the same.




Step 4: Now select the appdelegate file in your project the and create the object of this view just like this




try running your app, when you will hit the login button your application might crash and you will get the error message in your log only if NSZombie is enabled


You have got this message because of the way you have created the object of the LoginViewController, the view that you want to show in the iPhone window must be of strong reference and this is why your application crashed (For more details refer my earlier blog on strong and weak pointer reference) the code for the same is given below 

In the app delegate.h file



In the app Delegate.m file synthesize the property of the LoginViewController


After doing this update the code in the application did finish launching method


Step 5: Now you are ready to run your first ARC application go ahead and run your app everything will be just fine.

In my earlier post i have mentioned that not all third party libraries support the concept of ARC till now so for that when you convert the project into ARC then just uncheck those libraries which might give issue but make sure that in the Build Phases of your project you add a small command line. 


I hope that you have got the concept of ARC and how to create app and convert app using ARC, if you have any queries then kindly let me know via comment or via mails until then Happy iCoding and have a great day.

No comments:

Post a Comment