Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learning iOS: Part 1

Learning iOS: Part 1

This deck focuses on understanding some of the basics of Objective-C and how it is compiled for iOS.

Ryan Nystrom

January 25, 2013
Tweet

More Decks by Ryan Nystrom

Other Decks in Programming

Transcript

  1. NSString *a = @”Hello World!”; NSString *b = a; a

    = @”New world”; NSLog(@”%@”,b); // New world
  2. struct CGSize { CGFloat width; CGFloat height; }; CGSize size

    = { 100.f, 200.f }; size.width = 150.f;
  3. // avoid int i = 3; float f = 3.14f;

    // architecture safe NSInteger i = 3; CGFloat f = 3.14f; // legal i = f;
  4. // declare the class and superclass @interface MyObject : NSObject

    // public properties @property (strong, nonatomic) NSString *title; // method signatures - (void)doSomethingWithText:(NSString*)text; @end
  5. // create an object stored in memory MyObject *object =

    [[MyObject alloc] init]; // using an object’s property object.title = @"Hello World!"; // using an object’s methods [object doSomethingWithText:@”Change me”];
  6. one @property declaration sets up instance variable getter / setter

    thread safety retention / ownership (what)
  7. every time an object NSObject *object = [[NSObject alloc] init];

    // ref = 1 gets referenced anotherObject.property = object; // ref = 2
  8. every time an object NSObject *object = [[NSObject alloc] init];

    // ref = 1 gets referenced anotherObject.property = object; // ref = 2 that object’s reference count is increased
  9. NO