KEMBAR78
Objective-C Crash Course for Web Developers | KEY
Objective-C Crash Course




     for Web Developers
About me
About me

LinkedIn: jverbogt
Twitter: silentjohnny
Facebook: silentjohnny
E-mail: joris@mangrove.nl
History
iPhone SDK
AppStore
Build your own
TXXI
Today’s Topics
Today’s Topics
Today’s Topics

Native iPhone Development
Today’s Topics

Native iPhone Development
Live Demo
Today’s Topics

Native iPhone Development
Live Demo
Questions
iPhone Development
iPhone Development

Tools: Xcode / Interface Builder
iPhone Development

Tools: Xcode / Interface Builder
Language: Objective-C
iPhone Development

Tools: Xcode / Interface Builder
Language: Objective-C
Frameworks: Foundation / UIKit
Xcode
Xcode

Editor
Xcode

Editor
Debugger
Xcode

Editor
Debugger
Build Tools
Xcode

Editor
Debugger
Build Tools
Documentation
Interface Builder
Interface Builder

Design UI
Interface Builder

Design UI
Bind to code
Interface Builder

Design UI
Bind to code
Generate code
iPhone Simulator
iPhone Simulator

Easy for debugging
iPhone Simulator

Easy for debugging
No device needed
iPhone Simulator

Easy for debugging
No device needed
Fast round-trip
Not a real iPhone!
Objective-C
Objective-C
Objective-C

Superset of C, can be mixed
Objective-C

Superset of C, can be mixed
Simple syntax
Objective-C

Superset of C, can be mixed
Simple syntax
Dynamic runtime
OOP in Objective-C
OOP in Objective-C
OOP in Objective-C
Single inheritance class tree
OOP in Objective-C
Single inheritance class tree
Protocols for multi-class behavior
OOP in Objective-C
Single inheritance class tree
Protocols for multi-class behavior
Instance variables are hidden
OOP in Objective-C
Single inheritance class tree
Protocols for multi-class behavior
Instance variables are hidden
Objects respond to messages for interaction
OOP in Objective-C
Single inheritance class tree
Protocols for multi-class behavior
Instance variables are hidden
Objects respond to messages for interaction
Variables are bound to classes at runtime
OOP in Objective-C
Single inheritance class tree
Protocols for multi-class behavior
Instance variables are hidden
Objects respond to messages for interaction
Variables are bound to classes at runtime
There is an anonymous object type ‘id’
Syntax
Syntax
Syntax
float moneyInTheBank = 0.0;
Syntax
float moneyInTheBank = 0.0;

var moneyInTheBank = 0.0;
Syntax
Syntax
MacBookPro *myNewMac = [MacBookPro new];
Syntax
MacBookPro *myNewMac = [MacBookPro new];

var myNewMac = new MacBookPro();
Syntax
Syntax
if (moneyInTheBank > [myNewMac price]) {

    // Go buy one!

}
Syntax
if (moneyInTheBank > [myNewMac price]) {

    // Go buy one!

}


if (moneyInTheBank > myNewMac.getPrice()) {

    // Go buy one!

}
Syntax
Syntax
for (i=1; i<count; i++) {

}
Messaging
Messaging
Messaging
NSString *name = [person name];
Messaging
NSString *name = [person name];

var name = person.getName();
Messaging
Messaging
[person setName:@”John”];
Messaging
[person setName:@”John”];

person.setName(”John”);
Messaging
Messaging
NSUInteger length = [[person name] length];
Messaging
NSUInteger length = [[person name] length];

var length = person.getName().getLength();
Messaging
Messaging
[person setName:name andAge:21];
Messaging
[person setName:name andAge:21];

person.set({name:name, age:21});
Creating Instances
Creating Instances
Creating Instances
Person *person = [[Person alloc] init];
Creating Instances
Person *person = [[Person alloc] init];


Person *person = [Person new];
Creating Instances
Person *person = [[Person alloc] init];


Person *person = [Person new];


Person *person = [Person person];
Memory Management
Memory Management
Memory Management

 If you allocate memory,
 you need to clean it up!
Memory Management
Memory Management
NSObject *keepMe = [[NSObject alloc] init];
Memory Management
NSObject *keepMe = [[NSObject alloc] init];

[keepMe retain];
Memory Management
NSObject *keepMe = [[NSObject alloc] init];

[keepMe retain];

[keepMe autorelease];
Memory Management
NSObject *keepMe = [[NSObject alloc] init];

[keepMe retain];

[keepMe autorelease];

[keepMe release];
Memory Management
NSObject *keepMe = [[NSObject alloc] init];

[keepMe retain];

[keepMe autorelease];

[keepMe release];

NSObject *keepMe = [NSObject object];
Categories
Categories
Categories
Extending classes without subclassing
Categories
    Extending classes without subclassing

NSString *json = @”{“test”:”OK”}”;
Categories
    Extending classes without subclassing

NSString *json = @”{“test”:”OK”}”;

SBJsonParser *parser =

 [[SBJsonParser] alloc] init];

NSDictionary *data =

  [parser objectWithString:json];
Categories
    Extending classes without subclassing

NSString *json = @”{“test”:”OK”}”;



NSDictionary *data = [json JSONValue];
Categories
Categories
String.prototype.getJSONValue =

  function() { return ... };
Categories
String.prototype.getJSONValue =

  function() { return ... };



var json = “{”test”:”OK”}”;

var myObject = json.getJSONValue();
Foundation Classes
NSString
NSString
NSString
NSString *myName = @”joris”;
NSString
NSString *myName = @”joris”;

NSString *welcome = [NSString stringWithFormat:@”Hello %@”, name];
NSString
NSString *myName = @”joris”;

NSString *welcome = [NSString stringWithFormat:@”Hello %@”, name];



NSString *greeting = @”Hello ”;

NSString *welcome = [greeting stringByAppendingString:name];
NSString
NSString *myName = @”joris”;

NSString *welcome = [NSString stringWithFormat:@”Hello %@”, name];



NSString *greeting = @”Hello ”;

NSString *welcome = [greeting stringByAppendingString:name];



if ([myName isEqualToString:otherName]) {

    // Strings are equal!

}
NSArray
NSArray
NSArray
NSArray *myArray = [NSArray arrayWithObjects:@”me”, @”you”, nil];
NSArray
NSArray *myArray = [NSArray arrayWithObjects:@”me”, @”you”, nil];



NSUInteger count = [myArray count];
NSArray
NSArray *myArray = [NSArray arrayWithObjects:@”me”, @”you”, nil];



NSUInteger count = [myArray count];



NSString *secondItem = [myArray objectAtIndex:1];
NSArray
NSArray *myArray = [NSArray arrayWithObjects:@”me”, @”you”, nil];



NSUInteger count = [myArray count];



NSString *secondItem = [myArray objectAtIndex:1];



for (NSString *name in myArray) {

    NSLog(@”Name: %@”, name);

}
NSDictionary
NSDictionary
NSDictionary
NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:

              @”joris”, @”firstname”,

              @”verbogt”, @”lastname”,

              nil];
NSDictionary
NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:

              @”joris”, @”firstname”,

              @”verbogt”, @”lastname”,

              nil];



NSString *lastname = [myDict objectForKey:@”lastname”];
UIKit
Delegates
Delegates
Delegates

Many UIKit classes define delegate protocols
Delegates

Many UIKit classes define delegate protocols
No subclassing necessary for custom behavior
Delegates

Many UIKit classes define delegate protocols
No subclassing necessary for custom behavior
Loose coupling
Delegates

Many UIKit classes define delegate protocols
No subclassing necessary for custom behavior
Loose coupling
Easy refactoring
Connecting UI Elements
Connecting UI Elements
Connecting UI Elements

 Code defines outlets to UI elements
Connecting UI Elements

 Code defines outlets to UI elements
 Code responds to actions from UI
Connecting UI Elements

 Code defines outlets to UI elements
 Code responds to actions from UI
 UI Elements fire actions to a target
Connecting UI Elements

 Code defines outlets to UI elements
 Code responds to actions from UI
 UI Elements fire actions to a target
 Again: no subclassing
ViewControllers
ViewControllers
ViewControllers

Control a UI view (with sub-views)
ViewControllers

Control a UI view (with sub-views)
Ready to use, out-of-the-box
ViewControllers

Control a UI view (with sub-views)
Ready to use, out-of-the-box
Can be stacked for navigation
ViewControllers

Control a UI view (with sub-views)
Ready to use, out-of-the-box
Can be stacked for navigation
Can be initialized from code or IB
ViewControllers
ViewControllers

Useful Subclasses:
ViewControllers

Useful Subclasses:
   TableViewController
ViewControllers

Useful Subclasses:
   TableViewController
   NavigationController
ViewControllers

Useful Subclasses:
   TableViewController
   NavigationController
   TabBarController
Let’s do some coding...
Why?
Why?
Why?

Fun challenge
Why?

Fun challenge
Frameworks
Why?

Fun challenge
Frameworks
Best User Experience
Why?

Fun challenge
Frameworks
Best User Experience
Inspiration
Thank you
Copyright
Artwork by nozzman.com
Presentation by Joris Verbogt
This work is licensed under the Creative
Commons Attribution-Noncommercial-Share
Alike 3.0 Netherlands License.


Download at http://workshop.verbogt.nl/

Objective-C Crash Course for Web Developers

Editor's Notes

  • #4 Chief Developer Backend stuff / JavaScript integration
  • #19 Basic description
  • #22 Questions at the end Except for things that aren&amp;#x2019;t clear
  • #23 Questions at the end Except for things that aren&amp;#x2019;t clear
  • #24 Questions at the end Except for things that aren&amp;#x2019;t clear