Tuesday, August 10, 2010

Working with Xcode 4.5

The latest version of Xcode to develop application for iOS 6 is Xcode 4.5, Xcode is a very powerful tool to develope application for apple in a more elegant way.

In this tutorial we will learn on how to use this tool and will make an iphone application with one text field on to it so here's the tutorial i hope you like it.

UITextfield is a class which is belongs to the UIKit Framework it's just like your normal textbox, so now let's have a look at some of the basic functionality of UITextfield.

The UI in the UITextField class stands for User Interface

Here's the apple documentation for UITextField.

Open Xcode and select empty application

After doing this give your project an appropriate name i have used TextFieldDemo as the name of my project.

Also note that i have checked for ARC i.e automatic reference counting which means that i don't have to manually release any instance (Object) of a class that i create it will be automatically taken care of by the Xcode itself.

To know more about the ARC visit this link. 

Add a new file into your application of UIViewController type and to do this first you have to select the Objective C class from the iOS tab.

 Once you select the Objective C file type then given below is the next screen that you would see.

Remember: Make sure that in the Subclass section the selected class is UIViewController and if it's not then select it from the drop down menu.

I have given the name MyTextFieldVC now in the newly create file go to the MyTextFieldVC.h file thats the header file. 

Here you can see that just like in our earlier program we used to create a class which inherits from NSObject class here the class is already inherited from a class but this time its not NSObject its UIViewController.

To know about view and view controllers refer this link

Alright now coming to the coding part just open the Myview.h file and create an object of UITextfield class

now once you have declared the object of UITextfield now its time to use the object. We will go programmatically that means not using the Interface builder. 

First we will set the frame of text field and then set the boarder style and text of the text field. 

So now you select the .m file thats MyTextFieldVC.m and add the following code in the view did load method.

View did load: This method is called after your parent view is loaded in the memory, parent view is the view where you add all your other views like labels, textfield etc as a child view so that the user can interact with them.

Now your view is ready and all you have to do is add the parent view to the iPhone window.

The iPhone window object is present in the App delegate file of your project, so now kindly select the AppDelegate.h class file and add the following code.

Code Explanation: The current application supports ARC where weak reference are not allowed which means that you are telling your application that do not remove the object of a particular class which you have mentioned as a strong reference because you might be using it for further reference in your code.

Now inside the AppDelegate.m class file

but before that you have to import the MyTextFieldVC.h header file as you will be creating the object of MyTextFieldVC class.
in this function you load up your first view and put it in the window of iPhone

now all you have to do now is run the application by clicking Build and Go in order to run the iPhone simulator and see the output which will be like this

I hope that you have understood the concept on how to use Xcode, if their are any questions or queries then do let me know via mails or via comments.

Here's the demo code which you can download from here.

Until then Happy iCoding and have a great day.


  1. UseFul article :) as i am new to iPhone development this helps me alot

  2. I don't get why you have 2 times the "[window addSubview:obj.view];"...

  3. @Anonymous: I am sorry that was a mistake made by me will get it fixed you may look at the code now as i have edited it sorry for that mate.

    You need to add your view to the iPhone window only once not twice.

  4. AweSome tutorial for basic understanding of iphone application.

    Thanks a lot!!!.

  5. Nice flow of explanation, it will help us to understand the concept..Thanks ...

  6. Nice explanation.. Thank you