SlideShare une entreprise Scribd logo
1  sur  28
A Quick and Dirty Intro to
Objective C and iPhone
Programming
…or how I stopped worrying and learned to love Steve Jobs
What we’re going to cover
• Objective C basics
• iPhone library basics
• Writing an app
• Worshipping Steve Jobs
Objective C
• Another way of doing object oriented C
• Superset of the C language
• Uses the Smalltalk idea of message
passing rather than method invocation
• May look familiar to Vision users
Objective C
• Created in the early ’80s
• Adopted by NeXT in 1988
• Apple bought NeXT in 1996 and adopted
objective C as the language behind Mac
OS X
HAIL STEVE
KING OF NeXT!
Message Passing
• Instead of calling a function we send
messages to our object;
Foo *myObject;
...
[myObject doThingsWithArg:argument];
Object Selector Argument
Function Declaration
• More new syntax:
-(void) doThingsWithArg:(int)anArg;
Method
“scope”
Return Type Selector Argument type Argument name
Class Definitions
• Split into two files
.h – header
.m - implementation
Foo.h:
@interface Foo : NSObject {
int anInt;
NSString *aString;
}
-(void) doThingsWithArg:(int)anArg;
@end
Foo.m:
#import “Foo.h”
@implementation Foo
-(void) doThingsWithArg:(int)anArg {
…
}
@end
Constructors
• 2 part construction of objects
– Allocation: Allocation selector is “alloc”
– Initialisation: Initialisation selector is custom,
but always starts with “init” by convention.
• Constructors return ‘id’ type
• Standard construction line looks like:
[[myObject alloc] init];
Foo.h:
@interface Foo : NSObject {
int anInt;
NSString *aString;
}
-(id) init;
-(id) initWithArg:(int)arg
andArg:(NSString*)arg2;
-(void) doThingsWithArg:(int)anArg;
@end
Foo.m:
#import “Foo.h”
@implentation Foo
-(id) init {
return self;
}
-(id) initWithArg:(int)arg
andArg:(NSString*)arg2
{
anInt=arg;
aString=arg2;
return self;
}
-(void) doThingsWithArg:(int)anArg {…}
@end
Properties
• New in Objective C 2
– Released a couple of years back
• Automatic construction of accessors
• Must be declared in header and
‘synthesised’ in implementation
Foo.h:
@interface Foo : NSObject {
int anInt;
NSString *aString;
}
-(id) init;
-(id) initWithArg:(int)arg
andArg:(NSString*)arg2;
-(void) doThingsWithArg:(int)anArg;
@property (readwrite,assign) int anInt;
@property (readwrite,copy) NSString *aString;
@end
Foo.m:
#import “Foo.h”
@implentation Foo
@synthesize anInt;
@synthesize aString;
-(id) init {
[super init];
return self;
}
-(id) initWithArg:(int)arg
andArg:(NSString*)arg2
{
[super init];
myInstanceVar=arg;
aString=arg2;
return self;
}
-(void) doThingsWithArg:(int)anArg {…}
@end
Using our new object
Foo *myObj1=[[Foo alloc] init];
Foo *myObj2=[[Foo alloc] initWithArg:1
andArg:@”Pie”];
[myObj1 doStuffWithArg:23];
NSLog(@”%d and %@”,myObj2.anInt, myObj2.aString);
//prints out “1 and Pie”
NSLog(@”%d and %@”, [myObj2 getAnInt],
[myObj2 getAString]);
//also prints out “1 and Pie”
What was that assign/copy stuff?
• Objective C has a number of ways of
doing memory management
– Garbage collector
• New and not used everywhere
– Allocation pools
• Baby version of garbage collection
– Reference counting
• Used everywhere, including with pools and
garbage collection
What was that assign/copy stuff?
• When you get an object its reference
count is 1
• Use “retain” to add one to the count
• Use “release” to drop one from the count
• When count hits zero the object is
destroyed
– Destructor method is called ‘dealloc’
What was that assign/copy stuff?
• In properties you get to say how you want
the reference counts done
– Assign is a simple assignment, no reference
counting
– Retain returns the pointer to an object and
ups the reference count by 1 (for non-objects
this just works like assign)
– Copy returns a copy of the object
Reference counting
• This talk is called “quick and dirty”
because that’s all the memory
management I’m mentioning
• I’m still not sure when to retain things as
whether things are copied/retained/etc is
generally based on function naming
conventions.
– Lame
iPhone
• The iPhone uses Objective C and a bunch
of Apple libraries
• For many apps you can just bolt together
library bits with a little bit of extra logic and
data
The Steve says “LETS MAKE AN APP”
Going Further
• THE Cocoa programming book seems to
be:
Cocoa Programming for Mac OS X by Aaron Hillegass
Going Further
• Series of talks by Evan Doll and Alan
Cannistraro up on iTunes U
• Talks done at Stanford University in
Summer 2009 for the 2nd
year of their
iPhone programming course
• Missing some iPhone OS 3 features, but
very good.
Going Further
• Buy a Mac
• Make The Steve pleased
• Wear rollneck sweaters
• Conform
• Conform
• Conform
• Conform
• Conform
• Conform
• Conform
A quick and dirty intro to objective c

Contenu connexe

Tendances

Slicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPISlicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPIlestrrat
 
FlawDetector - Rubykaigi2013 LT
FlawDetector - Rubykaigi2013 LT FlawDetector - Rubykaigi2013 LT
FlawDetector - Rubykaigi2013 LT ginriki
 
Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Jeffrey Clark
 
Local search-based pattern matching features in EMF-IncQuery
Local search-based pattern matching features in EMF-IncQueryLocal search-based pattern matching features in EMF-IncQuery
Local search-based pattern matching features in EMF-IncQueryZoltán Ujhelyi
 
Take Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play FrameworkTake Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play FrameworkAsher Glynn
 
Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...Sergey Tihon
 

Tendances (7)

Slicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPISlicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPI
 
What's new in C# 8.0 (beta)
What's new in C# 8.0 (beta)What's new in C# 8.0 (beta)
What's new in C# 8.0 (beta)
 
FlawDetector - Rubykaigi2013 LT
FlawDetector - Rubykaigi2013 LT FlawDetector - Rubykaigi2013 LT
FlawDetector - Rubykaigi2013 LT
 
Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01
 
Local search-based pattern matching features in EMF-IncQuery
Local search-based pattern matching features in EMF-IncQueryLocal search-based pattern matching features in EMF-IncQuery
Local search-based pattern matching features in EMF-IncQuery
 
Take Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play FrameworkTake Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play Framework
 
Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...
 

Similaire à A quick and dirty intro to objective c

iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)Oliver Lin
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsPetr Dvorak
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective csagaroceanic11
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - CJussi Pohjolainen
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to DistributionTunvir Rahman Tusher
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone DevelopmentThoughtWorks
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingsana younas
 
Objective-C talk
Objective-C talkObjective-C talk
Objective-C talkbradringel
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CDataArt
 
Ios fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCIos fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCMadusha Perera
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
 
Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Altece
 
Introduction to Python Programing
Introduction to Python ProgramingIntroduction to Python Programing
Introduction to Python Programingsameer patil
 

Similaire à A quick and dirty intro to objective c (20)

Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 
Ios development
Ios developmentIos development
Ios development
 
iOS training (basic)
iOS training (basic)iOS training (basic)
iOS training (basic)
 
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
 
Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Pioc
PiocPioc
Pioc
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to Distribution
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
iOS Basic
iOS BasiciOS Basic
iOS Basic
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Objective-C talk
Objective-C talkObjective-C talk
Objective-C talk
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 
Ios fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCIos fundamentals with ObjectiveC
Ios fundamentals with ObjectiveC
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 
Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)
 
Introduction to Python Programing
Introduction to Python ProgramingIntroduction to Python Programing
Introduction to Python Programing
 

Dernier

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Dernier (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

A quick and dirty intro to objective c

  • 1. A Quick and Dirty Intro to Objective C and iPhone Programming …or how I stopped worrying and learned to love Steve Jobs
  • 2. What we’re going to cover • Objective C basics • iPhone library basics • Writing an app • Worshipping Steve Jobs
  • 3. Objective C • Another way of doing object oriented C • Superset of the C language • Uses the Smalltalk idea of message passing rather than method invocation • May look familiar to Vision users
  • 4. Objective C • Created in the early ’80s • Adopted by NeXT in 1988 • Apple bought NeXT in 1996 and adopted objective C as the language behind Mac OS X
  • 6. Message Passing • Instead of calling a function we send messages to our object; Foo *myObject; ... [myObject doThingsWithArg:argument]; Object Selector Argument
  • 7. Function Declaration • More new syntax: -(void) doThingsWithArg:(int)anArg; Method “scope” Return Type Selector Argument type Argument name
  • 8. Class Definitions • Split into two files .h – header .m - implementation
  • 9. Foo.h: @interface Foo : NSObject { int anInt; NSString *aString; } -(void) doThingsWithArg:(int)anArg; @end
  • 10. Foo.m: #import “Foo.h” @implementation Foo -(void) doThingsWithArg:(int)anArg { … } @end
  • 11. Constructors • 2 part construction of objects – Allocation: Allocation selector is “alloc” – Initialisation: Initialisation selector is custom, but always starts with “init” by convention. • Constructors return ‘id’ type • Standard construction line looks like: [[myObject alloc] init];
  • 12. Foo.h: @interface Foo : NSObject { int anInt; NSString *aString; } -(id) init; -(id) initWithArg:(int)arg andArg:(NSString*)arg2; -(void) doThingsWithArg:(int)anArg; @end
  • 13. Foo.m: #import “Foo.h” @implentation Foo -(id) init { return self; } -(id) initWithArg:(int)arg andArg:(NSString*)arg2 { anInt=arg; aString=arg2; return self; } -(void) doThingsWithArg:(int)anArg {…} @end
  • 14. Properties • New in Objective C 2 – Released a couple of years back • Automatic construction of accessors • Must be declared in header and ‘synthesised’ in implementation
  • 15. Foo.h: @interface Foo : NSObject { int anInt; NSString *aString; } -(id) init; -(id) initWithArg:(int)arg andArg:(NSString*)arg2; -(void) doThingsWithArg:(int)anArg; @property (readwrite,assign) int anInt; @property (readwrite,copy) NSString *aString; @end
  • 16. Foo.m: #import “Foo.h” @implentation Foo @synthesize anInt; @synthesize aString; -(id) init { [super init]; return self; } -(id) initWithArg:(int)arg andArg:(NSString*)arg2 { [super init]; myInstanceVar=arg; aString=arg2; return self; } -(void) doThingsWithArg:(int)anArg {…} @end
  • 17. Using our new object Foo *myObj1=[[Foo alloc] init]; Foo *myObj2=[[Foo alloc] initWithArg:1 andArg:@”Pie”]; [myObj1 doStuffWithArg:23]; NSLog(@”%d and %@”,myObj2.anInt, myObj2.aString); //prints out “1 and Pie” NSLog(@”%d and %@”, [myObj2 getAnInt], [myObj2 getAString]); //also prints out “1 and Pie”
  • 18. What was that assign/copy stuff? • Objective C has a number of ways of doing memory management – Garbage collector • New and not used everywhere – Allocation pools • Baby version of garbage collection – Reference counting • Used everywhere, including with pools and garbage collection
  • 19. What was that assign/copy stuff? • When you get an object its reference count is 1 • Use “retain” to add one to the count • Use “release” to drop one from the count • When count hits zero the object is destroyed – Destructor method is called ‘dealloc’
  • 20.
  • 21. What was that assign/copy stuff? • In properties you get to say how you want the reference counts done – Assign is a simple assignment, no reference counting – Retain returns the pointer to an object and ups the reference count by 1 (for non-objects this just works like assign) – Copy returns a copy of the object
  • 22. Reference counting • This talk is called “quick and dirty” because that’s all the memory management I’m mentioning • I’m still not sure when to retain things as whether things are copied/retained/etc is generally based on function naming conventions. – Lame
  • 23. iPhone • The iPhone uses Objective C and a bunch of Apple libraries • For many apps you can just bolt together library bits with a little bit of extra logic and data
  • 24. The Steve says “LETS MAKE AN APP”
  • 25. Going Further • THE Cocoa programming book seems to be: Cocoa Programming for Mac OS X by Aaron Hillegass
  • 26. Going Further • Series of talks by Evan Doll and Alan Cannistraro up on iTunes U • Talks done at Stanford University in Summer 2009 for the 2nd year of their iPhone programming course • Missing some iPhone OS 3 features, but very good.
  • 27. Going Further • Buy a Mac • Make The Steve pleased • Wear rollneck sweaters • Conform • Conform • Conform • Conform • Conform • Conform • Conform