iPhone Apps   A Closer Look
More about Obj-C Object Creation Two step process allocate memory initialize object + alloc class method that allocates memory for the object - init instance method to complete initialization
Creating Objects Person *person = nil; person = [[Person alloc] init];  OR  Person *person = [[Person alloc] init]; - (id)init { // allow superclass to initialize its state first if (self = [super init]) { age = 0; name = nil; } // do other initialization… return self }
Multiple init methods Classes may define multiple init methods - (id)init; - (id)initWithName:(NSString *)name; - (id)initWithName:(NSString *)name age:(int)age; person = [[Person alloc] init]; [person setName:@”MyName”]; [person setAge:24]; // Use ‘person’ object // What is next ? [person release];
Reference counting Every object has a “ retainCount ”  as long as  retainCount  is >  0 ,object is alive +alloc  and - copy  create objects with  retainCount   1 -retain  increments  retainCount -release  decrements  retainCount When  retainCount  reaches  0 , object is destroyed -dealloc  method invoked
Object deallocation #import "Person.h" @implementation Person -(void)dealloc { // Do any cleanup that’s necessary // when we’re done, call super to clean us up [super dealloc]; } @end You never call  dealloc  explicitly in your code You only deal with  alloc ,  copy ,  retain ,  release  to manage an object’s lifetime
iPhone v/s other patforms Only one application at a time Only one window Limited Access Limited Response Time Carefully craft Apps  Make sure data is not lost when user quits Limited System Resources RAM 128MB, Capacity 8GB ~70MB left for user applications No swap file
iPhone v/s other patforms . . . What you can ?  Photo Library Camera Location Services Address Book Accelerometer Many more . . .
ANATOMY OF AN  XCODE  PROJECT Main Components Classes Other Sources Resources Framework Product Target

Closer Look - iPhone programming

  • 1.
    iPhone Apps A Closer Look
  • 2.
    More about Obj-CObject Creation Two step process allocate memory initialize object + alloc class method that allocates memory for the object - init instance method to complete initialization
  • 3.
    Creating Objects Person*person = nil; person = [[Person alloc] init]; OR Person *person = [[Person alloc] init]; - (id)init { // allow superclass to initialize its state first if (self = [super init]) { age = 0; name = nil; } // do other initialization… return self }
  • 4.
    Multiple init methodsClasses may define multiple init methods - (id)init; - (id)initWithName:(NSString *)name; - (id)initWithName:(NSString *)name age:(int)age; person = [[Person alloc] init]; [person setName:@”MyName”]; [person setAge:24]; // Use ‘person’ object // What is next ? [person release];
  • 5.
    Reference counting Everyobject has a “ retainCount ” as long as retainCount is > 0 ,object is alive +alloc and - copy create objects with retainCount 1 -retain increments retainCount -release decrements retainCount When retainCount reaches 0 , object is destroyed -dealloc method invoked
  • 6.
    Object deallocation #import"Person.h" @implementation Person -(void)dealloc { // Do any cleanup that’s necessary // when we’re done, call super to clean us up [super dealloc]; } @end You never call dealloc explicitly in your code You only deal with alloc , copy , retain , release to manage an object’s lifetime
  • 7.
    iPhone v/s otherpatforms Only one application at a time Only one window Limited Access Limited Response Time Carefully craft Apps Make sure data is not lost when user quits Limited System Resources RAM 128MB, Capacity 8GB ~70MB left for user applications No swap file
  • 8.
    iPhone v/s otherpatforms . . . What you can ? Photo Library Camera Location Services Address Book Accelerometer Many more . . .
  • 9.
    ANATOMY OF AN XCODE PROJECT Main Components Classes Other Sources Resources Framework Product Target