iOS Application Development


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

iOS Application Development

  1. 1. iOS Application Development by Neha Goel
  2. 2. Agenda <ul><li>Learn about </li></ul><ul><li>LANGUAGE </li></ul><ul><li>FRAMEWORK </li></ul><ul><li>TOOLS </li></ul><ul><li>required for developing applications for iOS based </li></ul><ul><li>devices(iPhone, iPad and iPod Touch). </li></ul>
  3. 3. How to develop an application ?
  4. 4. STEP 1: Get a Mac System <ul><li>To develop iOS applications, you need a Mac with Mac OS X 10.6.6 or later. </li></ul>
  5. 5. STEP 2: Learn Objective C <ul><li>Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style </li></ul><ul><li>messaging to the C programming language. Today, it is used primarily on Apple's Mac OS </li></ul><ul><li>X and iOS: two environments based on the OpenStep standard, though not compliant with </li></ul><ul><li>it. Objective-C is the primary language used for Apple's Cocoa API. </li></ul><ul><li>SYNTAX: </li></ul><ul><li>Objective-C is a thin layer on top of C, and moreover is a strict superset of C; it is possible to </li></ul><ul><li>compile any C program with an Objective-C compiler, and to freely include C code within an </li></ul><ul><li>Objective-C class. </li></ul><ul><li>Objective-C derives its object syntax from Smalltalk. All of the syntax for non-object-oriented </li></ul><ul><li>operations (including primitive variables, pre-processing, expressions, function declarations, </li></ul><ul><li>and function calls) are identical to that of C, while the syntax for object-oriented features is </li></ul><ul><li>an implementation of Smalltalk-style messaging. </li></ul>
  6. 6. Create Interface File (.h) <ul><li>The interface of a class is usually defined in a header file . A common convention is to name the header file after the name of the class, e.g. Ball.h would contain the interface for the class Ball. </li></ul><ul><li>An interface declaration takes the form: </li></ul>@interface classname : superclass{ // instance variables(class members); } + (return_type) classMethod; + (return_type) classMethod1WithParameter1:(parm1_type)parm1 parameter2:(parm2_type)parm2; - (return_type) instanceMethod1WithParameter1:(parm1_type)parm1 parameter2:(parm2_type)parm2; @end In the above, plus signs denote class methods (class static functions), or methods that can be called without an instance of the class, and minus signs denote instance methods (instance member functions), which can only be called within a particular instance of the class. Class methods also have no access to instance variables. (int) addWithOperand1: (int) op1 operand2: (int) op2; (Objective-C Syntax) int add (int op1,op2); (C Syntax)
  7. 7. Create Implementation File (.m) <ul><li>The interface only declares the class interface and not the methods themselves: the actual code is written in the implementation file . Implementation (method) files normally have the file extension .m, which originally signified &quot;messages&quot; . </li></ul>#import “classname.h” @implementation classname + (return_type)classMethod { // implementation } - (return_type)instanceMethod { // implementation } @end Objective-C: (int) method :(int) i { return [self square_root:i]; } C : int function (int i) { return square_root(i); }
  8. 8. Methods <ul><li>The Objective-C programming language has the following particular syntax for applying methods to </li></ul><ul><li>classes and instances: </li></ul><ul><li>[ Class Or Instance method ]; </li></ul><ul><li>The Objective-C model of object-oriented programming is based on message passing to object </li></ul><ul><li>instances. In Objective-C one does not call a method; one sends a message . When you ask a class or </li></ul><ul><li>an instance to perform some action, you say that you are sending it a message; the recipient of that </li></ul><ul><li>message is called the receiver. So another way to look at the general format described previously is </li></ul><ul><li>as follows: </li></ul><ul><li>[ receiver message ] ; </li></ul>Sending the message method to the object pointed to by the pointer obj would require the following code in C++: obj->method(argument); In Objective-C, this is written as follows: [obj method: argument];
  9. 9. Instantiation <ul><li>Once an Objective-C class is written, it can be instantiated. This is done by first allocating the memory </li></ul><ul><li>for a new object and then by initializing it. An object is not fully functional until both steps have been </li></ul><ul><li>completed . These steps should be accomplished with a single line of code so that there is never </li></ul><ul><li>an allocated object that hasn't undergone initialization. </li></ul>
  10. 10. Init Equals to CONSTRUCTOR in C++ -(id)initWithName : (NSString *) newN ame{ self=[super init]; if(self){; } return self; } -(id)init{ self=[super init]; if(self){ } return self; }
  11. 11. Properties <ul><li>Objective-C 2.0 introduces a new syntax to declare instance variables as properties , with optional </li></ul><ul><li>attributes to configure the generation of accessor methods . Properties are, in a sense, public instance </li></ul><ul><li>variables; that is, declaring an instance variable as a property provides external classes with access </li></ul><ul><li>(possibly limited, e.g. read only) to that property. A property may be declared as &quot; readonly &quot;, and may be </li></ul><ul><li>provided with storage semantics such as &quot;assign&quot;, &quot;copy&quot; or &quot;retain&quot;. By default, properties are considered </li></ul><ul><li>atomic, which results in a lock preventing multiple threads from accessing them at the same time. A </li></ul><ul><li>property can be declared as &quot;nonatomic&quot;, which removes this lock. </li></ul>@interface Person : NSObject { NSString *name; int age; } @property(copy) NSString *name; @property(readonly) int age; -(id)initWithAge:(int)age; @end Properties are implemented by way of the @synthesize keyword, which generates getter and setter methods according to the property declaration. @implementation Person @synthesize name;
  12. 12. self Keyword @”MyName” It is equivalent to: [self setName:@”MyName”]; name= @”MyName” Assignment to iVar name. getter setter NSString *tempName=nil;; It is equivalent to: tempName=[self name];
  13. 13. Accessing Properties <ul><li>Properties can be accessed using the traditional message passing syntax , dot notation , or by </li></ul><ul><li>name via the &quot;valueForKey:&quot;/&quot;setValue:forKey:&quot; methods. </li></ul>Person *aPerson = [[Person alloc] initWithAge: 53]; = @&quot;Steve&quot;; // NOTE: dot notation, uses synthesized setter, equivalent to [aPerson setName: @&quot;Steve&quot;]; NSLog(@&quot;Access by message (%@), dot notation(%@), property name(%@) and direct instance variable access (%@)&quot;, [aPerson name],, [aPerson valueForKey:@&quot;name&quot;], aPerson->name);
  14. 14. Protocols <ul><li>A protocol is a list of methods that is shared among classes. The methods listed in the protocol do not </li></ul><ul><li>have corresponding implementations ; they’re meant to be implemented by someone else. A protocol </li></ul><ul><li>provides a way to define a set of methods that are somehow related with a specified name. The </li></ul><ul><li>methods are typically documented so that you know how they are to perform and so that you can </li></ul><ul><li>implement them in your own class definitions, if desired. If you decide to implement all of the required </li></ul><ul><li>methods for a particular protocol, you are said to conform to or adopt that protocol. </li></ul>
  15. 15. Syntax <ul><li>@protocol Printing </li></ul><ul><li>-(void) print; </li></ul><ul><li>@end </li></ul><ul><li>denotes that there is the abstract idea of displaying some text. By stating that the protocol is implemented </li></ul><ul><li>in the class definition: </li></ul><ul><li>@interface SomeClass : SomeSuperClass <Printing> </li></ul><ul><li>@end </li></ul><ul><li>#import “Printing.h” </li></ul><ul><li>@interface SomeClass </li></ul><ul><li>-(void) print{ </li></ul><ul><li>NSLog(@”IMPLEMENTING PRINT METHOD OF PRINTING PROTOCOL”); </li></ul><ul><li>} </li></ul><ul><li>@end </li></ul><ul><li>instances of SomeClass claim that they will provide an implementation for the instance method using </li></ul><ul><li>whatever means they choose. </li></ul>
  16. 16. id Data Type <ul><li>Objective-C provides a special type that can hold any object you can construct with Objective-C </li></ul><ul><li>regardless of class. This type is called id, and can be used to make your Objective-C programming </li></ul><ul><li>generic. </li></ul><ul><li>Let's look at an example of what is known as a container class , that is, a class that is used to hold an </li></ul><ul><li>object, perhaps in a certain data structure. </li></ul><ul><li>Say our container class is a linked list, and we have a linked list of LinkedListNode objects. We don't </li></ul><ul><li>know what data we might put into the linked list, so this suggests that we might use an id as a central </li></ul><ul><li>data type. Our interface then might look like </li></ul>@interface LinkedListNode : NSObject{ id data; LinkedListNode *next; } - (id) data; - (LinkedListNode *) next; @end
  17. 17. Cocoa/Cocoa Touch Cocoa is an application environment for both the Mac OS X operating system and iOS, the operating system used on Multi-Touch devices such as iPhone, iPad, and iPod touch. It consists of a suite of object-oriented software libraries, a runtime system, and an integrated development environment. Cocoa in the architecture of iOS
  18. 18. Core OS <ul><li>This level contains </li></ul><ul><li>the kernel </li></ul><ul><li>the file system </li></ul><ul><li>networking infrastructure </li></ul><ul><li>security </li></ul><ul><li>power management and </li></ul><ul><li>a number of device drivers. </li></ul><ul><li>It also has the libSystem library , which supports the POSIX/BSD </li></ul><ul><li>4.4/C99 API specifications and includes system-level APIs for many </li></ul><ul><li>services. </li></ul>
  19. 19. Core Services <ul><li>The frameworks in this layer provide core services, such as </li></ul><ul><li>string manipulation </li></ul><ul><li>collection management </li></ul><ul><li>networking </li></ul><ul><li>URL utilities </li></ul><ul><li>contact management and </li></ul><ul><li>preferences. </li></ul><ul><li>They also provide services based on hardware features of a device, such as the GPS, compass, </li></ul><ul><li>accelerometer, and gyroscope. </li></ul><ul><li>Examples of frameworks in this layer are Core Location , Core Motion , and System Configuration . </li></ul><ul><li>This layer includes both Foundation and Core Foundation frameworks that provide abstractions for </li></ul><ul><li>common data types such as strings and collections. </li></ul><ul><li>The Core Frameworks layer also contains Core Data , a framework for object graph management </li></ul><ul><li>and object persistence. </li></ul>
  20. 20. Media <ul><li>The frameworks and services in this layer depend on the Core Services layer </li></ul><ul><li>and provide graphical and multimedia services to the Cocoa Touch layer. </li></ul><ul><li>They include </li></ul><ul><li>Core Graphics </li></ul><ul><li>Core Text </li></ul><ul><li>OpenGL ES </li></ul><ul><li>Core Animation </li></ul><ul><li>AVFoundation </li></ul><ul><li>Core Audio and </li></ul><ul><li>Video Playback. </li></ul>
  21. 21. Cocoa Touch <ul><li>The frameworks in this layer directly support applications based in iOS. They include </li></ul><ul><li>frameworks such as Game Kit, Map Kit and iAd . </li></ul><ul><li>The Cocoa Touch layer and the Core Services layer each has an Objective-C framework </li></ul><ul><li>that is especially important for developing applications for iOS. These are the core Cocoa </li></ul><ul><li>frameworks in iOS : </li></ul><ul><li>UIKit.: </li></ul><ul><li>This framework provides the objects an application displays in its user interface and defines </li></ul><ul><li>the structure for application behavior, including event handling and drawing. </li></ul><ul><li>Foundation: </li></ul><ul><li>This framework defines the basic behavior of objects, establishes mechanisms for their </li></ul><ul><li>management, and provides objects for primitive data types, collections, and operating- </li></ul><ul><li>system services. </li></ul>
  22. 22. Model View Controller(Composite Design Pattern) App Delegate( .h/.m) ViewController (.h/.m) View (.xib) Model(.h/.m)
  23. 23. Lets build Hello World ! <ul><li>DEMO </li></ul>