SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Chap 4
Objective-C Classes
Interface and
            implementation
@interface MyClass : NSObject
-(NSString*) sayGoodnightJames;
@end
@implementation MyClass {
    // instance variable declarations go here (starting in iOS5)
}
-(NSString*) sayGoodnightJames {
    return @”Good night, James!”;
}
@end
.h & .m files
        @interface MyClass : NSObject
abc.h   -(NSString*) sayGoodnightJames;
        @end
        @implementation MyClass {
            // instance variable declarations go here (starting in iOS5)
        }
abc.m   -(NSString*) sayGoodnightJames {
            return @”Good night, James!”;
        }
        @end
Cocoa’s Own Header
        Files
Cocoa’s Own Header
        Files

• You can’t see the source code for Cocoa.
Cocoa’s Own Header
        Files

• You can’t see the source code for Cocoa.
• Rely purely on the documentation (and
  experimentation).
Cocoa’s Own Header
        Files

• You can’t see the source code for Cocoa.
• Rely purely on the documentation (and
  experimentation).
• Can only see the Cocoa header files.
Class Methods
Class Methods
•   Factory method
Class Methods
•   Factory method

    •   UIFont has a class method fontWithName:size:
Class Methods
•   Factory method

    •   UIFont has a class method fontWithName:size:
    •   Supply a name and a size, and return a UIFont
        object.
Class Methods
•   Factory method

    •   UIFont has a class method fontWithName:size:
    •   Supply a name and a size, and return a UIFont
        object.
•   Global utility method
Class Methods
•   Factory method

    •   UIFont has a class method fontWithName:size:
    •   Supply a name and a size, and return a UIFont
        object.
•   Global utility method
    •   Good place to put a utility method.
Class Methods
•   Factory method

    •   UIFont has a class method fontWithName:size:
    •   Supply a name and a size, and return a UIFont
        object.
•   Global utility method
    •   Good place to put a utility method.
    •   Doesn’t require the overhead of an instance.
Chap 5
Objective-C Instances
How instance are
   created
How instance are
       created
• Ready-Made Instances
How instance are
       created
• Ready-Made Instances
 • NSString* s2 = [s uppercaseString];
How instance are
       created
• Ready-Made Instances
 • NSString* s2 = [s uppercaseString];
• Instatiation from scratch
How instance are
        created
• Ready-Made Instances
 • NSString* s2 = [s uppercaseString];
• Instatiation from scratch
 •   SomeClass* aVariable = [[SomeClass alloc] init];
How instance are
        created
• Ready-Made Instances
 • NSString* s2 = [s uppercaseString];
• Instatiation from scratch
 •   SomeClass* aVariable = [[SomeClass alloc] init];

• Nib-Based Instantiation (見下頁)
Intialization (P. 79)
NSArray* pep =

[NSArray arrayWithObjects:@”cho”, @”james”,
@”calvin”,@”crux”, nil];




NSArray* pep =

[[NSArray alloc] initWithObjects:@”cho”, @”james”,
@”calvin”,@”crux”, nil];
Nib-Based Instatiation
When the app runs and a nib file is loaded,
those classes are instantiated and initialized.
(P. 80 Figure 5-1)
UIButton* b =

  [UIButton buttonWithType:UIButtonTypeRoundedRect]; //factory method

[b setTitle:@”Hello!” forState:UIControlStateNormal]; //set up title

[b setFrame: CGRectMake(100,100,100,35)]; //set up frame

[view addSubview:b]; //place a button in view
Polymorphism
UIButton* b = [UIButton buttonWithType:UIButtonTypeRoundedRect];

UIView* v = b;

[v setTitle:@”James!” forState:UIControlStateNormal];

//compiler will complain!
Polymorphism (cont.)
UIButton* b = [UIButton buttonWithType:UIButtonTypeRoundedRect];

UIView* v = b;

[(UIButton*)v setTitle:@”James!” forState:UIControlStateNormal];

//compiler is happy!
Keyword: self
@implementation MyClass
-(NSString*) greeting {
    return @”Good night, James!”;
}
-(NSString*) sayGoodNightJames {
    return [self greeting];
}
@end
Keyword: self (cont.)
@implemtation Dog

-(NSString*) bark {

    return @”Hi, James”;

}

-(NSString*) speak {

    return [self bark];

}

@end

(P. 85 Figure 5-2)
Keyword: self (conc.)
@implemtation Basenji : Dog

-(NSString*) bark {

    return @””;      //Empty string, Basenjis can’t bark.

}

@end

Basenji* b = [[Basenji alloc] init];

(P. 85 Figure 5-2)
Keyword: super
@implemtation NoisyDog : Dog

-(NSString*) bark {

  return [NSString stringWithFormat: @”%@ %@”, [super bark], [super
bark]];

}

@end

(P. 88 a UIView Controller example)
Instance Variables and
      Accessors
@implementation Dog {
    // ivars can now be declared in the implementation section
    int number;
}
-(void) setNumber: (int) n {
     self->number = n;
}
-(int) number {
     return self->number;
}
@end
Instance Variables and
      Accessors
Dog* fido = [[Dog alloc] init];

[fido setNumber: 42];

int n = [fido number];

//n = 42!
Properties
@property(nonatomic) UIViewAutoresizing autoresizingMask

@property(nonatomic) int number

fido.number = 43;

int n = fido.number;

Weitere ähnliche Inhalte

Was ist angesagt?

Django rest framework tips and tricks
Django rest framework   tips and tricksDjango rest framework   tips and tricks
Django rest framework tips and tricksxordoquy
 
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 MinutesDjangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 MinutesNina Zakharenko
 
Automated testing with RSpec
Automated testing with RSpecAutomated testing with RSpec
Automated testing with RSpecNascenia IT
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたmemememomo
 
2017 JCP EC: Configuration JSR
2017 JCP EC: Configuration JSR2017 JCP EC: Configuration JSR
2017 JCP EC: Configuration JSRDavid Blevins
 
Love / Hate Puppet (Puppet Gotchas)
Love / Hate Puppet (Puppet Gotchas)Love / Hate Puppet (Puppet Gotchas)
Love / Hate Puppet (Puppet Gotchas)Puppet
 
WordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 MeetupWordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 Meetupl3rady
 
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーSatoshi Asano
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love RubyBen Scheirman
 
Everybody Loves AFNetworking ... and So Can you!
Everybody Loves AFNetworking ... and So Can you!Everybody Loves AFNetworking ... and So Can you!
Everybody Loves AFNetworking ... and So Can you!jeffsoto
 
Extracting ruby gem
Extracting ruby gemExtracting ruby gem
Extracting ruby gemYura Tolstik
 
Modernizes your objective C - Oliviero
Modernizes your objective C - OlivieroModernizes your objective C - Oliviero
Modernizes your objective C - OlivieroCodemotion
 
2011/10/08_Playframework_GAE_to_Heroku
2011/10/08_Playframework_GAE_to_Heroku2011/10/08_Playframework_GAE_to_Heroku
2011/10/08_Playframework_GAE_to_HerokuTakeshi Hagikura
 

Was ist angesagt? (20)

RSpec 2 Best practices
RSpec 2 Best practicesRSpec 2 Best practices
RSpec 2 Best practices
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
Django rest framework tips and tricks
Django rest framework   tips and tricksDjango rest framework   tips and tricks
Django rest framework tips and tricks
 
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 MinutesDjangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
 
Automated testing with RSpec
Automated testing with RSpecAutomated testing with RSpec
Automated testing with RSpec
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
 
Impression of Rails 3
Impression of Rails 3Impression of Rails 3
Impression of Rails 3
 
2017 JCP EC: Configuration JSR
2017 JCP EC: Configuration JSR2017 JCP EC: Configuration JSR
2017 JCP EC: Configuration JSR
 
Voyage by example
Voyage by exampleVoyage by example
Voyage by example
 
Love / Hate Puppet (Puppet Gotchas)
Love / Hate Puppet (Puppet Gotchas)Love / Hate Puppet (Puppet Gotchas)
Love / Hate Puppet (Puppet Gotchas)
 
WordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 MeetupWordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 Meetup
 
Introduction to Underscore.js
Introduction to Underscore.jsIntroduction to Underscore.js
Introduction to Underscore.js
 
Go database/sql
Go database/sqlGo database/sql
Go database/sql
 
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
 
Djangocon
DjangoconDjangocon
Djangocon
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Everybody Loves AFNetworking ... and So Can you!
Everybody Loves AFNetworking ... and So Can you!Everybody Loves AFNetworking ... and So Can you!
Everybody Loves AFNetworking ... and So Can you!
 
Extracting ruby gem
Extracting ruby gemExtracting ruby gem
Extracting ruby gem
 
Modernizes your objective C - Oliviero
Modernizes your objective C - OlivieroModernizes your objective C - Oliviero
Modernizes your objective C - Oliviero
 
2011/10/08_Playframework_GAE_to_Heroku
2011/10/08_Playframework_GAE_to_Heroku2011/10/08_Playframework_GAE_to_Heroku
2011/10/08_Playframework_GAE_to_Heroku
 

Andere mochten auch

20120720品牌原來如此分享
20120720品牌原來如此分享20120720品牌原來如此分享
20120720品牌原來如此分享Giga Cheng
 
Jakobsena polacco pp
Jakobsena polacco ppJakobsena polacco pp
Jakobsena polacco ppjakobsena
 
More Guns, Less Crime
More Guns, Less CrimeMore Guns, Less Crime
More Guns, Less Crimetwnicely
 
2caldecottbooks
2caldecottbooks2caldecottbooks
2caldecottbooksjakobsena
 
資金不是創業最難的事, 擁抱夢想創業
資金不是創業最難的事, 擁抱夢想創業資金不是創業最難的事, 擁抱夢想創業
資金不是創業最難的事, 擁抱夢想創業Giga Cheng
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
Il gladiatore, l'età imperiale attraverso il film di Ridley Scott
Il gladiatore, l'età imperiale attraverso il film di Ridley Scott Il gladiatore, l'età imperiale attraverso il film di Ridley Scott
Il gladiatore, l'età imperiale attraverso il film di Ridley Scott ali94
 
[KSG知識分享會]20120720品牌原來如此分享
[KSG知識分享會]20120720品牌原來如此分享[KSG知識分享會]20120720品牌原來如此分享
[KSG知識分享會]20120720品牌原來如此分享Giga Cheng
 

Andere mochten auch (10)

20120720品牌原來如此分享
20120720品牌原來如此分享20120720品牌原來如此分享
20120720品牌原來如此分享
 
Jakobsena polacco pp
Jakobsena polacco ppJakobsena polacco pp
Jakobsena polacco pp
 
More Guns, Less Crime
More Guns, Less CrimeMore Guns, Less Crime
More Guns, Less Crime
 
Surabh airtel
Surabh airtelSurabh airtel
Surabh airtel
 
2caldecottbooks
2caldecottbooks2caldecottbooks
2caldecottbooks
 
資金不是創業最難的事, 擁抱夢想創業
資金不是創業最難的事, 擁抱夢想創業資金不是創業最難的事, 擁抱夢想創業
資金不是創業最難的事, 擁抱夢想創業
 
6 mathematics of_life1
6 mathematics of_life16 mathematics of_life1
6 mathematics of_life1
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Il gladiatore, l'età imperiale attraverso il film di Ridley Scott
Il gladiatore, l'età imperiale attraverso il film di Ridley Scott Il gladiatore, l'età imperiale attraverso il film di Ridley Scott
Il gladiatore, l'età imperiale attraverso il film di Ridley Scott
 
[KSG知識分享會]20120720品牌原來如此分享
[KSG知識分享會]20120720品牌原來如此分享[KSG知識分享會]20120720品牌原來如此分享
[KSG知識分享會]20120720品牌原來如此分享
 

Ähnlich wie Objective C 基本介紹

Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersJoris Verbogt
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS EngineZongXian Shen
 
Intro to iPhone Development
Intro to iPhone DevelopmentIntro to iPhone Development
Intro to iPhone DevelopmentMichael Koby
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design PatternsAlex Theedom
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextMugunth Kumar
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patternsAlex Theedom
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Conceptsmdfkhan625
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns Alex Theedom
 
Spring 3.0 dependancy injection
Spring 3.0 dependancy injectionSpring 3.0 dependancy injection
Spring 3.0 dependancy injectionRajiv Gupta
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java conceptsChikugehlot
 
Frederick web meetup slides
Frederick web meetup slidesFrederick web meetup slides
Frederick web meetup slidesPat Zearfoss
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-CKazunobu Tasaka
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Barcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationBarcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationSociable
 
Cappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application FrameworkCappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application FrameworkAndreas Korth
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016Alex Theedom
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 

Ähnlich wie Objective C 基本介紹 (20)

Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web Developers
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
 
Intro to iPhone Development
Intro to iPhone DevelopmentIntro to iPhone Development
Intro to iPhone Development
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design Patterns
 
Fwt ios 5
Fwt ios 5Fwt ios 5
Fwt ios 5
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreText
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns
 
Spring 3.0 dependancy injection
Spring 3.0 dependancy injectionSpring 3.0 dependancy injection
Spring 3.0 dependancy injection
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Frederick web meetup slides
Frederick web meetup slidesFrederick web meetup slides
Frederick web meetup slides
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Barcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentationBarcamp Auckland Rails3 presentation
Barcamp Auckland Rails3 presentation
 
Cappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application FrameworkCappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application Framework
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 

Kürzlich hochgeladen

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
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
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Kürzlich hochgeladen (20)

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
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
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

Objective C 基本介紹

  • 2. Interface and implementation @interface MyClass : NSObject -(NSString*) sayGoodnightJames; @end @implementation MyClass { // instance variable declarations go here (starting in iOS5) } -(NSString*) sayGoodnightJames { return @”Good night, James!”; } @end
  • 3. .h & .m files @interface MyClass : NSObject abc.h -(NSString*) sayGoodnightJames; @end @implementation MyClass { // instance variable declarations go here (starting in iOS5) } abc.m -(NSString*) sayGoodnightJames { return @”Good night, James!”; } @end
  • 5. Cocoa’s Own Header Files • You can’t see the source code for Cocoa.
  • 6. Cocoa’s Own Header Files • You can’t see the source code for Cocoa. • Rely purely on the documentation (and experimentation).
  • 7. Cocoa’s Own Header Files • You can’t see the source code for Cocoa. • Rely purely on the documentation (and experimentation). • Can only see the Cocoa header files.
  • 9. Class Methods • Factory method
  • 10. Class Methods • Factory method • UIFont has a class method fontWithName:size:
  • 11. Class Methods • Factory method • UIFont has a class method fontWithName:size: • Supply a name and a size, and return a UIFont object.
  • 12. Class Methods • Factory method • UIFont has a class method fontWithName:size: • Supply a name and a size, and return a UIFont object. • Global utility method
  • 13. Class Methods • Factory method • UIFont has a class method fontWithName:size: • Supply a name and a size, and return a UIFont object. • Global utility method • Good place to put a utility method.
  • 14. Class Methods • Factory method • UIFont has a class method fontWithName:size: • Supply a name and a size, and return a UIFont object. • Global utility method • Good place to put a utility method. • Doesn’t require the overhead of an instance.
  • 16. How instance are created
  • 17. How instance are created • Ready-Made Instances
  • 18. How instance are created • Ready-Made Instances • NSString* s2 = [s uppercaseString];
  • 19. How instance are created • Ready-Made Instances • NSString* s2 = [s uppercaseString]; • Instatiation from scratch
  • 20. How instance are created • Ready-Made Instances • NSString* s2 = [s uppercaseString]; • Instatiation from scratch • SomeClass* aVariable = [[SomeClass alloc] init];
  • 21. How instance are created • Ready-Made Instances • NSString* s2 = [s uppercaseString]; • Instatiation from scratch • SomeClass* aVariable = [[SomeClass alloc] init]; • Nib-Based Instantiation (見下頁)
  • 22. Intialization (P. 79) NSArray* pep = [NSArray arrayWithObjects:@”cho”, @”james”, @”calvin”,@”crux”, nil]; NSArray* pep = [[NSArray alloc] initWithObjects:@”cho”, @”james”, @”calvin”,@”crux”, nil];
  • 23. Nib-Based Instatiation When the app runs and a nib file is loaded, those classes are instantiated and initialized. (P. 80 Figure 5-1) UIButton* b = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //factory method [b setTitle:@”Hello!” forState:UIControlStateNormal]; //set up title [b setFrame: CGRectMake(100,100,100,35)]; //set up frame [view addSubview:b]; //place a button in view
  • 24. Polymorphism UIButton* b = [UIButton buttonWithType:UIButtonTypeRoundedRect]; UIView* v = b; [v setTitle:@”James!” forState:UIControlStateNormal]; //compiler will complain!
  • 25. Polymorphism (cont.) UIButton* b = [UIButton buttonWithType:UIButtonTypeRoundedRect]; UIView* v = b; [(UIButton*)v setTitle:@”James!” forState:UIControlStateNormal]; //compiler is happy!
  • 26. Keyword: self @implementation MyClass -(NSString*) greeting { return @”Good night, James!”; } -(NSString*) sayGoodNightJames { return [self greeting]; } @end
  • 27. Keyword: self (cont.) @implemtation Dog -(NSString*) bark { return @”Hi, James”; } -(NSString*) speak { return [self bark]; } @end (P. 85 Figure 5-2)
  • 28. Keyword: self (conc.) @implemtation Basenji : Dog -(NSString*) bark { return @””; //Empty string, Basenjis can’t bark. } @end Basenji* b = [[Basenji alloc] init]; (P. 85 Figure 5-2)
  • 29. Keyword: super @implemtation NoisyDog : Dog -(NSString*) bark { return [NSString stringWithFormat: @”%@ %@”, [super bark], [super bark]]; } @end (P. 88 a UIView Controller example)
  • 30. Instance Variables and Accessors @implementation Dog { // ivars can now be declared in the implementation section int number; } -(void) setNumber: (int) n { self->number = n; } -(int) number { return self->number; } @end
  • 31. Instance Variables and Accessors Dog* fido = [[Dog alloc] init]; [fido setNumber: 42]; int n = [fido number]; //n = 42!

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n