iOS Development

Tuesday 25th of December 2012 08:43:13 PM

  Toggle Advanced Options

iOS 7 (interesting new features and APIs)

  • UI redesign
  • Multitasking enhancements (both push and pull)
  • AirDrop (sharing data with nearby devices)
  • Peer-to-Peer connectivity (without requiring Internet connectivity)

Objective-C development

Class header (.h)

#import "HeaderFile.h"

@interface ClassName : SuperClass 
    // Declare instance variables (optional)

// Define properties
// Define methods (including any custom initializers)


Class implementation (.m)

#import "ClassName.h"

@implementation ClassName

// Synthesize properties (optional in Xcode 4.4+)
// Implement methods (including any custom initializers, and dealloc)


Defining methods

- (type)doIt;
- (type)doItWithA:(type)a;
- (type)doItWithA:(type)a andB:(type)b;

Implementing methods

- (type)doItWithA:(type)a andB:(type)b 
    // Do something with a and b...
    return returnValue;

Calling a method

[myClass doIt];
[myClass doItWithA:a];
[myClass doItWithA:a andB:b];

Creating a class instance

ClassName * myClass = [[ClassName alloc] init];

Defining properties

@property (attribute1, attribute2) propertyName;


  • Multithreading
    • nonatomic: not threadsafe, increases performance
    • atomic: threadsafe, default for properties
  • Lifetime specifiers
    • strong: ensures that a strong reference is kept to the passed-in object.
    • weak: synthesize a setter that sets the property to the passed-in object; if this object is deallocated, the property will be set to nil
    • assign: normal assign, no reference, default for properties
    • copy: make copy on assign
  • Mutability
    • readwrite: create both a getter and a setter, default for properties
    • readonly: create just the getter

Synthesizing properties

// Optional in Xcode 4.4+
@synthesize propertyName;
@synthesize propertyName = _myInstanceVariable;

Using properties

[myClass setPropertyName:a]; // setter
myClass.propertyName = a; // alternative (dot-notation) setter

a = [myClass propertyName]; // getter
a = test.propertyName; // alternative (dot-notation) getter

Declaring variables

type myVariable;


  • int: 1, 2, 500, 1000000
  • float / double: 1.5, 3.14159265
  • ClassName *: NSString *, NSArray, etcetera
  • id: Can hold a reference to any object

Custom initializer example

- (id)initWithParam:(type)param 
    if ((self = [super init])) {
        [self setPropertyName:param];
    return self;