Objective-C – Blocks

Objective-C Blocks ”; Previous Next An Objective-C class defines an object that combines data with related behavior. Sometimes, it makes sense just to represent a single task or unit of behavior, rather than a collection of methods. Blocks are a language-level feature added to C, Objective-C and C++ which allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. Blocks are Objective-C objects which means they can be added to collections like NSArray or NSDictionary. They also have the ability to capture values from the enclosing scope, making them similar to closures or lambdas in other programming languages Simple Block declaration syntax returntype (^blockName)(argumentType); Simple block implementation returntype (^blockName)(argumentType)= ^{ }; Here is a simple example void (^simpleBlock)(void) = ^{ NSLog(@”This is a block”); }; We can invoke the block using simpleBlock(); Blocks Take Arguments and Return Values Blocks can also take arguments and return values just like methods and functions. Here is a simple example to implement and invoke a block with arguments and return values. double (^multiplyTwoValues)(double, double) = ^(double firstValue, double secondValue) { return firstValue * secondValue; }; double result = multiplyTwoValues(2,4); NSLog(@”The result is %f”, result); Blocks Using Type Definitions Here is a simple example using typedef in block. Please note this sample doesn”t work on the online compiler for now. Use XCode to run the same. #import <Foundation/Foundation.h> typedef void (^CompletionBlock)(); @interface SampleClass:NSObject – (void)performActionWithCompletion:(CompletionBlock)completionBlock; @end @implementation SampleClass – (void)performActionWithCompletion:(CompletionBlock)completionBlock { NSLog(@”Action Performed”); completionBlock(); } @end int main() { /* my first program in Objective-C */ SampleClass *sampleClass = [[SampleClass alloc]init]; [sampleClass performActionWithCompletion:^{ NSLog(@”Completion is called to intimate action is performed.”); }]; return 0; } Let us compile and execute it, it will produce the following result − 2013-09-10 08:13:57.155 demo[284:303] Action Performed 2013-09-10 08:13:57.157 demo[284:303] Completion is called to intimate action is performed. Blocks are used more in iOS applications and Mac OS X. So its more important to understand the usage of blocks. Print Page Previous Next Advertisements ”;

Objective-C – Loops

Objective-C Loops ”; Previous Next There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages − Objective-C programming language provides the following types of loop to handle looping requirements. Click the following links to check their details. Sr.No. Loop Type & Description 1 while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. 2 for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable. 3 do…while loop Like a while statement, except that it tests the condition at the end of the loop body. 4 nested loops You can use one or more loops inside any another while, for or do..while loop. Loop Control Statements Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Objective-C supports the following control statements. Click the following links to check their details. Sr.No. Control Statement & Description 1 break statement Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. 2 continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. The Infinite Loop A loop becomes infinite loop if a condition never becomes false. The for loop is traditionally used for this purpose. Since none of the three expressions that form the for loop are required, you can make an endless loop by leaving the conditional expression empty. #import <Foundation/Foundation.h> int main () { for( ; ; ) { NSLog(@”This loop will run forever.n”); } return 0; } When the conditional expression is absent, it is assumed to be true. You may have an initialization and increment expression, but Objective-C programmers more commonly use the for(;;) construct to signify an infinite loop. Print Page Previous Next Advertisements ”;

Objective-C – Functions

Objective-C Functions ”; Previous Next A function is a group of statements that together perform a task. Every Objective-C program has one C function, which is main(), and all of the most trivial programs can define additional functions. You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is so each function performs a specific task. A function declaration tells the compiler about a function”s name, return type, and parameters. A function definition provides the actual body of the function. Basically in Objective-C, we call the function as method. The Objective-C foundation framework provides numerous built-in methods that your program can call. For example, method appendString() to append string to another string. A method is known with various names like a function or a sub-routine or a procedure, etc. Defining a Method The general form of a method definition in Objective-C programming language is as follows − – (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 … joiningArgumentn:( argumentTypen )argumentNamen { body of the function } A method definition in Objective-C programming language consists of a method header and a method body. Here are all the parts of a method − Return Type − A method may return a value. The return_type is the data type of the value the function returns. Some methods perform the desired operations without returning a value. In this case, the return_type is the keyword void. Method Name − This is the actual name of the method. The method name and the parameter list together constitute the method signature. Arguments − A argument is like a placeholder. When a function is invoked, you pass a value to the argument. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the arguments of a method. Arguments are optional; that is, a method may contain no argument. Joining Argument − A joining argument is to make it easier to read and to make it clear while calling it. Method Body − The method body contains a collection of statements that define what the method does. Example Following is the source code for a method called max(). This method takes two parameters num1 and num2 and returns the maximum between the two − /* function returning the max between two numbers */ – (int) max:(int) num1 secondNumber:(int) num2 { /* local variable declaration */ int result; if (num1 > num2) { result = num1; } else { result = num2; } return result; } Method Declarations A method declaration tells the compiler about a function name and how to call the method. The actual body of the function can be defined separately. A method declaration has the following parts − – (return_type) function_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 … joiningArgumentn:( argumentTypen )argumentNamen; For the above-defined function max(), following is the method declaration − -(int) max:(int)num1 andNum2:(int)num2; Method declaration is required when you define a method in one source file and you call that method in another file. In such case you should declare the function at the top of the file calling the function. Calling a method While creating a Objective-C method, you give a definition of what the function has to do. To use a method, you will have to call that function to perform the defined task. When a program calls a function, program control is transferred to the called method. A called method performs defined task, and when its return statement is executed or when its function-ending closing brace is reached, it returns program control back to the main program. To call a method, you simply need to pass the required parameters along with method name, and if method returns a value, then you can store returned value. For example − Live Demo #import <Foundation/Foundation.h> @interface SampleClass:NSObject /* method declaration */ – (int)max:(int)num1 andNum2:(int)num2; @end @implementation SampleClass /* method returning the max between two numbers */ – (int)max:(int)num1 andNum2:(int)num2 { /* local variable declaration */ int result; if (num1 > num2) { result = num1; } else { result = num2; } return result; } @end int main () { /* local variable definition */ int a = 100; int b = 200; int ret; SampleClass *sampleClass = [[SampleClass alloc]init]; /* calling a method to get max value */ ret = [sampleClass max:a andNum2:b]; NSLog(@”Max value is : %dn”, ret ); return 0; } I kept max() function along with main() function and complied the source code. While running final executable, it would produce the following result − 2013-09-07 22:28:45.912 demo[26080] Max value is : 200 Function Arguments If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables are called the formal parameters of the function. The formal parameters behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit. While calling a function, there are two ways that arguments can be passed to a function − Sr.No. Call Type & Description 1 Call by value This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. 2 Call by reference This method copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument. By default, Objective-C uses call by value to pass arguments. In general, this means that code within a function cannot alter the arguments used to call the function, and above-mentioned example while calling max() function used the same method. Print Page Previous Next Advertisements ”;

Objective-C – Strings

Objective-C Strings ”; Previous Next The string in Objective-C programming language is represented using NSString and its subclass NSMutableString provides several ways for creating string objects. The simplest way to create a string object is to use the Objective-C @”…” construct − NSString *greeting = @”Hello”; A simple example for creating and printing a string is shown below. Live Demo #import <Foundation/Foundation.h> int main () { NSString *greeting = @”Hello”; NSLog(@”Greeting message: %@n”, greeting ); return 0; } When the above code is compiled and executed, it produces result something as follows − 2013-09-11 01:21:39.922 demo[23926] Greeting message: Hello Objective-C supports a wide range of methods for manipulate strings − Sr.No. Method & Purpose 1 – (NSString *)capitalizedString; Returns a capitalized representation of the receiver. 2 – (unichar)characterAtIndex:(NSUInteger)index; Returns the character at a given array position. 3 – (double)doubleValue; Returns the floating-point value of the receiver’s text as a double. 4 – (float)floatValue; Returns the floating-point value of the receiver’s text as a float. 5 – (BOOL)hasPrefix:(NSString *)aString; Returns a Boolean value that indicates whether a given string matches the beginning characters of the receiver. 6 – (BOOL)hasSuffix:(NSString *)aString; Returns a Boolean value that indicates whether a given string matches the ending characters of the receiver. 7 – (id)initWithFormat:(NSString *)format …; Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted. 8 – (NSInteger)integerValue; Returns the NSInteger value of the receiver’s text. 9 – (BOOL)isEqualToString:(NSString *)aString; Returns a Boolean value that indicates whether a given string is equal to the receiver using a literal Unicode-based comparison. 10 – (NSUInteger)length; Returns the number of Unicode characters in the receiver. 11 – (NSString *)lowercaseString; Returns lowercased representation of the receiver. 12 – (NSRange)rangeOfString:(NSString *)aString; Finds and returns the range of the first occurrence of a given string within the receiver. 13 – (NSString *)stringByAppendingFormat:(NSString *)format …; Returns a string made by appending to the receiver a string constructed from a given format string and the following arguments. 14 – (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set; Returns a new string made by removing from both ends of the receiver characters contained in a given character set. 15 – (NSString *)substringFromIndex:(NSUInteger)anIndex; Returns a new string containing the characters of the receiver from the one at a given index to the end. Following example makes use of few of the above-mentioned functions − Live Demo #import <Foundation/Foundation.h> int main () { NSString *str1 = @”Hello”; NSString *str2 = @”World”; NSString *str3; int len ; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; /* uppercase string */ str3 = [str2 uppercaseString]; NSLog(@”Uppercase String : %@n”, str3 ); /* concatenates str1 and str2 */ str3 = [str1 stringByAppendingFormat:@”World”]; NSLog(@”Concatenated string: %@n”, str3 ); /* total length of str3 after concatenation */ len = [str3 length]; NSLog(@”Length of Str3 : %dn”, len ); /* InitWithFormat */ str3 = [[NSString alloc] initWithFormat:@”%@ %@”,str1,str2]; NSLog(@”Using initWithFormat: %@n”, str3 ); [pool drain]; return 0; } When the above code is compiled and executed, it produces result something as follows − 2013-09-11 01:15:45.069 demo[30378] Uppercase String : WORLD 2013-09-11 01:15:45.070 demo[30378] Concatenated string: HelloWorld 2013-09-11 01:15:45.070 demo[30378] Length of Str3 : 10 2013-09-11 01:15:45.070 demo[30378] Using initWithFormat: Hello World You can find a complete list of Objective-C NSString related methods in NSString Class Reference. Print Page Previous Next Advertisements ”;

Objective-C – Operators

Objective-C Operators ”; Previous Next An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Objective-C language is rich in built-in operators and provides following types of operators − Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Misc Operators This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one. Arithmetic Operators Following table shows all the arithmetic operators supported by Objective-C language. Assume variable A holds 10 and variable B holds 20, then − Show Examples Operator Description Example + Adds two operands A + B will give 30 – Subtracts second operand from the first A – B will give -10 * Multiplies both operands A * B will give 200 / Divides numerator by denominator B / A will give 2 % Modulus Operator and remainder of after an integer division B % A will give 0 ++ Increment operator increases integer value by one A++ will give 11 — Decrement operator decreases integer value by one A– will give 9 Relational Operators Following table shows all the relational operators supported by Objective-C language. Assume variable A holds 10 and variable B holds 20, then − Show Examples Operator Description Example == Checks if the values of two operands are equal or not; if yes, then condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not; if values are not equal, then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand; if yes, then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand; if yes, then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand; if yes, then condition becomes true. (A <= B) is true. Logical Operators Following table shows all the logical operators supported by Objective-C language. Assume variable A holds 1 and variable B holds 0, then − Show Examples Operator Description Example && Called Logical AND operator. If both the operands are non zero then condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. (A || B) is true. ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false. !(A && B) is true. Bitwise Operators Bitwise operator works on bits and perform bit by bit operation. The truth tables for &, |, and ^ are as follows − p q p & q p | q p ^ q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 Assume if A = 60; and B = 13; now in binary format they will be as follows − A = 0011 1100 B = 0000 1101 —————– A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~A  = 1100 0011 The Bitwise operators supported by Objective-C language are listed in the following table. Assume variable A holds 60 and variable B holds 13 then − Show Examples Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12, which is 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61, which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49, which is 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of ”flipping” bits. (~A ) will give -61, which is 1100 0011 in 2”s complement form. << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240, which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15, which is 0000 1111 Assignment Operators There are following assignment operators supported by Objective-C language − Show Examples Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assign value of A + B into C += Add AND assignment operator, It adds right operand to the left operand and assigns the result to left operand C += A is equivalent to C = C + A -= Subtract AND assignment operator, It subtracts right operand from the left operand and assigns the result to left operand C -= A is equivalent to C = C – A *= Multiply AND assignment operator, It multiplies right operand with the left operand and assigns the result to left operand C *= A is equivalent to C = C * A /= Divide AND assignment operator, It divides left operand with the right operand and assigns the result to left operand C /= A is equivalent to C = C / A %= Modulus AND assignment operator, It takes modulus using two operands and assigns the result to left operand C %= A is equivalent to C = C % A <<= Left shift AND assignment operator C <<= 2 is same as C = C << 2 >>= Right shift AND assignment operator

Objective-C – Data Encapsulation

Objective-C Data Encapsulation ”; Previous Next All Objective-C programs are composed of the following two fundamental elements − Program statements (code) − This is the part of a program that performs actions and they are called methods. Program data − The data is the information of the program which is affected by the program functions. Encapsulation is an Object-Oriented Programming concept that binds together the data and functions that manipulate the data and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding. Data encapsulation is a mechanism of bundling the data and the functions that use them, and data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user. Objective-C supports the properties of encapsulation and data hiding through the creation of user-defined types, called classes. For example − @interface Adder : NSObject { NSInteger total; } – (id)initWithInitialNumber:(NSInteger)initialNumber; – (void)addNumber:(NSInteger)newNumber; – (NSInteger)getTotal; @end The variable total is private and we cannot access from outside the class. This means that they can be accessed only by other members of the Adder class and not by any other part of your program. This is one way encapsulation is achieved. Methods inside the interface file are accessible and are public in scope. There are private methods, which are written with the help of extensions, which we will learn in upcoming chapters. Data Encapsulation Example Any Objective-C program where you implement a class with public and private members variables is an example of data encapsulation and data abstraction. Consider the following example − Live Demo #import <Foundation/Foundation.h> @interface Adder : NSObject { NSInteger total; } – (id)initWithInitialNumber:(NSInteger)initialNumber; – (void)addNumber:(NSInteger)newNumber; – (NSInteger)getTotal; @end @implementation Adder -(id)initWithInitialNumber:(NSInteger)initialNumber { total = initialNumber; return self; } – (void)addNumber:(NSInteger)newNumber { total = total + newNumber; } – (NSInteger)getTotal { return total; } @end int main(int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Adder *adder = [[Adder alloc]initWithInitialNumber:10]; [adder addNumber:5]; [adder addNumber:4]; NSLog(@”The total is %ld”,[adder getTotal]); [pool drain]; return 0; } When the above code is compiled and executed, it produces the following result − 2013-09-22 21:17:30.485 DataEncapsulation[317:303] The total is 19 Above class adds numbers together and returns the sum. The public members addNum and getTotal are the interfaces to the outside world and a user needs to know them to use the class. The private member total is something that is hidden from the outside world, but is needed for the class to operate properly. Designing Strategy Most of us have learned through bitter experience to make class members private by default unless we really need to expose them. That”s just good encapsulation. It”s important to understand data encapsulation since it”s one of the core features of all Object-Oriented Programming (OOP) languages including Objective-C. Print Page Previous Next Advertisements ”;

Objective-C – Error Handling

Objective-C Error Handling ”; Previous Next In Objective-C programming, error handling is provided with NSError class available in Foundation framework. An NSError object encapsulates richer and more extensible error information than is possible using only an error code or error string. The core attributes of an NSError object are an error domain (represented by a string), a domain-specific error code and a user info dictionary containing application specific information. NSError Objective-C programs use NSError objects to convey information about runtime errors that users need to be informed about. In most cases, a program displays this error information in a dialog or sheet. But it may also interpret the information and either ask the user to attempt to recover from the error or attempt to correct the error on its own NSError Object consists of − Domain − The error domain can be one of the predefined NSError domains or an arbitrary string describing a custom domain and domain must not be nil. Code − The error code for the error. User Info − The userInfo dictionary for the error and userInfo may be nil. The following example shows how to create a custom error NSString *domain = @”com.MyCompany.MyApplication.ErrorDomain”; NSString *desc = NSLocalizedString(@”Unable to complete the process”, @””); NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : desc }; NSError *error = [NSError errorWithDomain:domain code:-101 userInfo:userInfo]; Here is complete code of the above error sample passed as reference to an pointer − Live Demo #import <Foundation/Foundation.h> @interface SampleClass:NSObject -(NSString *) getEmployeeNameForID:(int) id withError:(NSError **)errorPtr; @end @implementation SampleClass -(NSString *) getEmployeeNameForID:(int) id withError:(NSError **)errorPtr { if(id == 1) { return @”Employee Test Name”; } else { NSString *domain = @”com.MyCompany.MyApplication.ErrorDomain”; NSString *desc =@”Unable to complete the process”; NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:desc, @”NSLocalizedDescriptionKey”,NULL]; *errorPtr = [NSError errorWithDomain:domain code:-101 userInfo:userInfo]; return @””; } } @end int main() { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; SampleClass *sampleClass = [[SampleClass alloc]init]; NSError *error = nil; NSString *name1 = [sampleClass getEmployeeNameForID:1 withError:&error]; if(error) { NSLog(@”Error finding Name1: %@”,error); } else { NSLog(@”Name1: %@”,name1); } error = nil; NSString *name2 = [sampleClass getEmployeeNameForID:2 withError:&error]; if(error) { NSLog(@”Error finding Name2: %@”,error); } else { NSLog(@”Name2: %@”,name2); } [pool drain]; return 0; } In the above example, we return a name if the id is 1, otherwise we set the user-defined error object. When the above code is compiled and executed, it produces the following result − 2013-09-14 18:01:00.809 demo[27632] Name1: Employee Test Name 2013-09-14 18:01:00.809 demo[27632] Error finding Name2: Unable to complete the process Print Page Previous Next Advertisements ”;

Objective-C – Polymorphism

Objective-C Polymorphism ”; Previous Next The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. Objective-C polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. Consider the example, we have a class Shape that provides the basic interface for all the shapes. Square and Rectangle are derived from the base class Shape. We have the method printArea that is going to show about the OOP feature polymorphism. Live Demo #import <Foundation/Foundation.h> @interface Shape : NSObject { CGFloat area; } – (void)printArea; – (void)calculateArea; @end @implementation Shape – (void)printArea { NSLog(@”The area is %f”, area); } – (void)calculateArea { } @end @interface Square : Shape { CGFloat length; } – (id)initWithSide:(CGFloat)side; – (void)calculateArea; @end @implementation Square – (id)initWithSide:(CGFloat)side { length = side; return self; } – (void)calculateArea { area = length * length; } – (void)printArea { NSLog(@”The area of square is %f”, area); } @end @interface Rectangle : Shape { CGFloat length; CGFloat breadth; } – (id)initWithLength:(CGFloat)rLength andBreadth:(CGFloat)rBreadth; @end @implementation Rectangle – (id)initWithLength:(CGFloat)rLength andBreadth:(CGFloat)rBreadth { length = rLength; breadth = rBreadth; return self; } – (void)calculateArea { area = length * breadth; } @end int main(int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Shape *square = [[Square alloc]initWithSide:10.0]; [square calculateArea]; [square printArea]; Shape *rect = [[Rectangle alloc] initWithLength:10.0 andBreadth:5.0]; [rect calculateArea]; [rect printArea]; [pool drain]; return 0; } When the above code is compiled and executed, it produces the following result − 2013-09-22 21:21:50.785 Polymorphism[358:303] The area of square is 100.000000 2013-09-22 21:21:50.786 Polymorphism[358:303] The area is 50.000000 In the above example based on the availability of the method calculateArea and printArea, either the method in the base class or the derived class executed. Polymorphism handles the switching of methods between the base class and derived class based on the method implementation of the two classes. Print Page Previous Next Advertisements ”;

Objective-C – Overview

Objective-C Overview ”; Previous Next Objective-C is general-purpose language that is developed on top of C Programming language by adding features of Small Talk programming language making it an object-oriented language. It is primarily used in developing iOS and Mac OS X operating systems as well as its applications. Initially, Objective-C was developed by NeXT for its NeXTSTEP OS from whom it was taken over by Apple for its iOS and Mac OS X. Object-Oriented Programming Objective-C fully supports object-oriented programming, including the four pillars of object-oriented development − Encapsulation Data hiding Inheritance Polymorphism Example Code #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@”hello world”); [pool drain]; return 0; } Foundation Framework Foundation Framework provides large set of features and they are listed below. It includes a list of extended datatypes like NSArray, NSDictionary, NSSet and so on. It consists of a rich set of functions manipulating files, strings, etc. It provides features for URL handling, utilities like date formatting, data handling, error handling, etc. Learning Objective-C The most important thing to do when learning Objective-C is to focus on concepts and not get lost in language technical details. The purpose of learning a programming language is to become a better programmer; that is, to become more effective at designing and implementing new systems and at maintaining old ones. Use of Objective-C Objective-C, as mentioned earlier, is used in iOS and Mac OS X. It has large base of iOS users and largely increasing Mac OS X users. And since Apple focuses on quality first and its wonderful for those who started learning Objective-C. Print Page Previous Next Advertisements ”;

Objective-C – Home

Objective-C Tutorial PDF Version Quick Guide Resources Job Search Discussion Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. This is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch. This reference will take you through simple and practical approach while learning Objective-C Programming language. Audience This reference has been prepared for the beginners to help them understand the basic to advanced concepts related to Objective-C Programming languages. Prerequisites Before you start doing practice with various types of examples given in this reference, I”m making an assumption that you are already aware about what is a computer program and what is a computer programming language? Print Page Previous Next Advertisements ”;