iPhone Development Intro




                      www.braceta.com
Luis Azevedo    www.twitter.com/braceta
Overview

• Tools/SDK
• Setting up
• Objective-C
• Demo?
Setting up...
Setting up...
• Get a Mac
Setting up...
• Get a Mac
• Get the SDK
Setting up...
• Get a Mac
• Get the SDK
• Install
Setting up...
• Get a Mac
• Get the SDK
• Install
• Get an Apple Developer Connection
  account
Setting up...
• Get a Mac
• Get the SDK
• Install
• Get an Apple Developer Connection
  account
Setting up...
• Get a Mac
• Get the SDK
• Install
• Get an Apple Developer Connection €€€
  account
Setting up...
• Get a Mac
• Get the SDK
• Install
• Get an Apple Developer Connection €€€
  account
• Code
Setting up...
• Get a Mac
• Get the SDK
• Install
• Get an Apple Developer Connection €€€
  account
• Code
• Profit?
Tools/SDK

• Xcode
• iPhone/iPod or iPad
• Interface Builder
• iPhone Simulator
• Instruments
Xcode
Simulator
Interface Builder
Instruments
Languages

•C
• C++
• Objective-C
• Objective-C++
Objective-C
    History
C   Smalltalk
C   Smalltalk




     Objective-C
C   Smalltalk




     Objective-C

                C++
C   Smalltalk




     Objective-C

                C++

           Java    C#
C   Smalltalk




     Objective-C

                C++

           Java    C#
C   Smalltalk




     Objective-C

                C++

           Java    C#
Objective-C
   Description
Objective-C
Objective-C
• OOP
Objective-C
• OOP
• Dynamic
Objective-C
• OOP
• Dynamic
• based on message passing
Objective-C
• OOP
• Dynamic
• based on message passing
• single inherance
Objective-C
• OOP
• Dynamic
• based on message passing
• single inherance
• Protocols and Categories
Objective-C
• OOP
• Dynamic
• based on message passing
• single inherance
• Protocols and Categories
• full of [] and @s
Files


• .h - Header files
• .m - Class implementation files
Objective-C
    Sintax
Syntax Examples
Syntax Examples
[object method];
Syntax Examples
[object method];
int value = [object method];
Syntax Examples
[object method];
int value = [object method];
[object method:argument];
Syntax Examples
[object method];
int value = [object method];
[object method:argument];
[[object method] method2];
Syntax Examples
[object method];
int value = [object method];
[object method:argument];
[[object method] method2];
[object method:argument option:anotherArg];
.m file


- (id) thisIsAMethod:(int)param1
                 options:(float)param2
.m file


- (id) thisIsAMethod:(int)param1
                 options:(float)param2

 {
     for (int n = 0; n < 10; ++n)
     {
         NSLog(@”N=%d”, n);
         [object callMethod:1 thing:2];
     }
 }
.m file
@implementation MyClass
- (id) thisIsAMethod:(int)param1
                 options:(float)param2

 {
       for (int n = 0; n < 10; ++n)
       {
           NSLog(@”N=%d”, n);
           [object callMethod:1 thing:2];
       }
 }
@end
.m file
@implementation MyClass
- (id) thisIsAMethod:(int)param1
        @class     options:(float)param2
        @interface
  {
        @end
      for (int n = 0; n < 10; ++n)
      { @property
           NSLog(@”N=%d”, n);
        @private
           [object callMethod:1 thing:2];
      } @protected
  }
@end
.m file
@implementation MyClass
- (id) thisIsAMethod:(int)param1
                 options:(float)param2

 {
       for (int n = 0; n < 10; ++n)
       {
           NSLog(@”N=%d”, n);
           [object callMethod:1 thing:2];
       }
 }
@end
.m file
@implementation MyClass
- (id) thisIsAMethod:(int)param1
                 options:(float)param2

 {
       for (int n = 0; n < 10; ++n)
       {
           NSLog(@”N=%d”, n);
           [object callMethod:1 thing:2];
       }
 }
@end
.m file
@implementation MyClass
- (id) thisIsAMethod:(int)param1
                 options:(float)param2

 {
       for (int n = 0; n < 10; ++n)
       {
           NSLog(@”N=%d”, n);
           [object callMethod:1 thing:2];
       }
 }
@end
.m file
@implementation MyClass
- (id) thisIsAMethod:(int)param1
                 options:(float)param2

 {
       for (int n = 0; n < 10; ++n)
       {
        NSString
             NSLog(@”N=%d”, n);
             [object callMethod:1 thing:2];
       }
 }
@end
.h file
#import <Foundation/Foundation.h>

@interface MyClass : NSObject
{
      NSDictionary *member;
      bool otherMember;
}
- (void) init;
- (id) initWithItems:(NSArray*)array
               enabled:(bool)enabled;

+ (id) myClassWithItems:(NSArray*)array;

@end
.h file
#import <Foundation/Foundation.h>

@interface MyClass : NSObject
{
      NSDictionary *member;
      bool otherMember;
}
- (void) init;
- (id) initWithItems:(NSArray*)array
               enabled:(bool)enabled;

+ (id) myClassWithItems:(NSArray*)array;

@end
.h file
#import <Foundation/Foundation.h>

@interface MyClass : NSObject
{
      NSDictionary *member;
      bool otherMember;
}
- (void) init;
- (id) initWithItems:(NSArray*)array
               enabled:(bool)enabled;

+ (id) myClassWithItems:(NSArray*)array;

@end
.h file
#import <Foundation/Foundation.h>

@interface MyClass : NSObject
{
      NSDictionary *member;
      bool otherMember;
}
- (void) init;
- (id) initWithItems:(NSArray*)array
               enabled:(bool)enabled;

+ (id) myClassWithItems:(NSArray*)array;

@end
.h file
#import <Foundation/Foundation.h>

@interface MyClass : NSObject
{
      NSDictionary *member;
      bool otherMember;
}
- (void) init;
- (id) initWithItems:(NSArray*)array
               enabled:(bool)enabled;

+ (id) myClassWithItems:(NSArray*)array;

@end
Syntax Examples

// Create MyClass instance
MyClass *myClass = [[MyClass alloc] init];
Properties
@interface MyClass
{
    int harold;
}

@property (nonatomic,retain) int age;

@end

// In MyClass.m...

@interface MyClass
@synthesize age;
@end
Properties


[myClass setAge:20];
myClass.age = 20; // is calling setAge
Categories

@interface NSObject (Foo)
- (void) extraFooMethod;
@end
Categories
@interface NSObject (Foo)
- (void) extraFooMethod;
@end


NSArray *array = [NSArray array];
[array extraFooMethod];
iOS Development
iOS Frameworks
iOS Frameworks

     Cocoa Touch
iOS Frameworks

                   UIKit, MapKit, Printing,
     Cocoa Touch   Gesture Recognizers
iOS Frameworks

                   UIKit, MapKit, Printing,
     Cocoa Touch   Gesture Recognizers



       Media
iOS Frameworks

                   UIKit, MapKit, Printing,
     Cocoa Touch   Gesture Recognizers



                   Core Audio, Open GL ES,
       Media       Quartz, Core Animation
iOS Frameworks

                    UIKit, MapKit, Printing,
     Cocoa Touch    Gesture Recognizers



                    Core Audio, Open GL ES,
       Media        Quartz, Core Animation




    Core Services
iOS Frameworks

                    UIKit, MapKit, Printing,
     Cocoa Touch    Gesture Recognizers



                    Core Audio, Open GL ES,
       Media        Quartz, Core Animation


                    Core Data, Core
    Core Services   Foundation, Address Book
                    Framework
iOS Frameworks

                    UIKit, MapKit, Printing,
     Cocoa Touch    Gesture Recognizers



                    Core Audio, Open GL ES,
       Media        Quartz, Core Animation


                    Core Data, Core
    Core Services   Foundation, Address Book
                    Framework



      Core OS
iOS Frameworks

                    UIKit, MapKit, Printing,
     Cocoa Touch    Gesture Recognizers



                    Core Audio, Open GL ES,
       Media        Quartz, Core Animation


                    Core Data, Core
    Core Services   Foundation, Address Book
                    Framework



      Core OS       Posix Threads, SQLite
iOS Frameworks

                              UIKit, MapKit, Printing,
Objective C   Cocoa Touch     Gesture Recognizers



                              Core Audio, Open GL ES,
                 Media        Quartz, Core Animation


                              Core Data, Core
              Core Services   Foundation, Address Book
                              Framework




   C            Core OS       Posix Threads, SQLite
UIKit
UIKit
MVC Pattern
MVC Pattern




Model
MVC Pattern
            View




Model
MVC Pattern
            View




Model              Controller
MVC Pattern
            View




Model              Controller
MVC Pattern
            View




Model              Controller
Views
Views
• UIView class
Views
• UIView class
• View Object is a rectangle on the screen
Views
• UIView class
• View Object is a rectangle on the screen
• Handles touch events
Views
• UIView class
• View Object is a rectangle on the screen
• Handles touch events
• Can be container for other views
Views
• UIView class
• View Object is a rectangle on the screen
• Handles touch events
• Can be container for other views
• Can be created programatically or with
  Interface Builder
Views
• UIView class
• View Object is a rectangle on the screen
• Handles touch events
• Can be container for other views
• Can be created programatically or with
  Interface Builder
• Can be animated using Core Animations
Views
ViewControllers
ViewControllers
• iOS Controllers are ViewControllers
ViewControllers
• iOS Controllers are ViewControllers
• Descendant of UIViewController
ViewControllers
• iOS Controllers are ViewControllers
• Descendant of UIViewController
• Provides all the logic to bridge data from
  the model and the view
ViewControllers
• iOS Controllers are ViewControllers
• Descendant of UIViewController
• Provides all the logic to bridge data from
  the model and the view
• Loads Views
ViewControllers
• iOS Controllers are ViewControllers
• Descendant of UIViewController
• Provides all the logic to bridge data from
  the model and the view
• Loads Views
• Implements the code to handle actions
  triggered by touch events on views
ViewController
.XIB Files
.XIB Files

• Interface Builder XML GUI spec files
.XIB Files

• Interface Builder XML GUI spec files
• Connects from IB to the Code
.XIB Files

• Interface Builder XML GUI spec files
• Connects from IB to the Code
• Only on iOS. At build time are converted
  to NIB files
Demo
Resources
Beggining iPhone 3 Development
   Dave Mark | Jeff LaMarche
 http://iphonedevelopment.blogspot.com/
Resources
Facebook Three20 Obj-C
      Framework

https://github.com/facebook/three20
Q&A

iPhone Development Intro