Advertisement

iOS

iPhone SDK: Using Existing Objective-C Classes

Class | Foundation | IOS | IPhone | NSDate | NSString | Objective-C | Xcode

iPhone Application Development

Advertisement

This entry is part 5 of 9 in the series iPhone Application Development

The Foundation framework contains lots of predefined objective-c classes that we can use like NSString, NSDate etc. Let’s create a program that uses built-in objective-c classes.

Using Existing Objective-C Classes

Step 1. Create new Project in Xcode with command line tool template and write code in main method.

 

First we created NSString class’s object called name and set String value to “Ronak Prajapati”. Then we called name object’s instance method uppercaseString, which return string in upper case letters and store in new object called uname.

Syntax for calling instance method or say message:

[Object method_name];

You can see the whole documentation of any class and for that you don’t have to search it on google or apple documentation website. It’s very easy. Just alt+click on class name in code.

iPhone Objective-c classes

 

Clicking on the book icon from the right top corner of the popup, bring you to the full documentation of that particular class. This contains all methods that are available for us in NSString class. Scroll down till you find the changing case section. Where you can see the uppercaseString Method signature. Which looks like this:

iPhone Objective-c classes

 

Step 2. Now lets output the new uname object using NSLog.

This will output: Your Name is RONAK PRAJAPATI

Step 3. Now create another object of say NSDate type

NSDate has a class method called date, which returns current system date. We store that returned date in object d1 and then output using NSLog.

Syntax for calling class method or say message:

[classname method_name];

Let’s quickly hit run and see how it outputs.

iPhone Objective-c classes

 

Note: There are lots of built-in objective-c classes in foundation framework, which we can use in any Objective-C program. Full documentation is available for us and it’s easy to access by alt+clicking on class name.  You don’t have to learn every class and memorize it. It’s very hard, it takes lots of time and it’s not convenient way to developing iPhone application. Just make sure that whenever you need help regarding any class it’s there for you.

Series Navigation<< iPhone SDK: Objective-C Creating Custom ClassiPhone SDK: Your First iPhone Application >>iPhone SDK: MVC in iPhone Application Development >>

Bookmark Link using: bookmark at folkd