SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Object C
                 Bit Academy
Object C
               •   C                    80
                          Brad J. Cox

               •   1980                      NextStep


               •   Object C
•           :       (
                   ,           )

               •       :
•
               •
                                                    0


               •
                                   .

               • Car *myCar = [[Car alloc] init];
•                : alloc (call retain)

               •                : release

               •   Car *myCar = [[Car alloc] init];

               •   printf(“The retain count is %dn”, [myCar retainCount]);

               •   [myCar release];

               •   printf(“Retain count is now %dn”, [myCar retainCount]); //error

               •                                        ,         retain      release
,           ,

               •          :

               •          :


               •          :

               •              : initWithName: andModel:
                   andYear: (                     )
•
               •
                   .
•   .h

               •             -

               •        +

               •        .m
• .m (                                                                           )
               #import “Car.h”
               @implementation Car

               -(id) init                    The init method defined in the NSObject class
                                               does no initialization, it simply returns self
               {
                   self = [super init];
                   if(!self) = return nil;

                   make = nil;
                   model = nil;
                   year = 1901;
                   return self;
               }
[obj method_name];
          obj :
          method_name          .
•   +       . +(NSString *) motto;

               •   [   _           _        ]

               •
                   •
                   •

                   •
+ (NSString *) motto
               {
                  return (@”Ford Prefects are Mostly Harmless”);
               }

               [Car motto];


                                                                   .
               [UIApplication sharedApplication];
               [UIDevice currentDevice];



               [[NSArray alloc] init];
               [NSArray array]; ->
                                                                       .
•
               •
                    C

               •            -C           factory,   factory
                   method

               •                                              .

               •

               •   NSObject      class
                      .
alloc
               class
•   +
               •

               •
•            -C
                   static


               •
               •                 ,
for/in                                   for loop

               NSArray *colors = [NSArray arrayWithObjects:@”Blacks”,
               @”Silver”, @”Gray”, nil];
               for (NSString *color in colors)
               {
                  printf(“Consider buying a %s car”, [color UTF8String]);
               }
NSObject


                          NSArray     NSString    UIResponder

                                                   UIView


                                     UILabel      UIControl

                                    UITextField    UISlider




               object C                                             .

                                                   .
                                                                .
NSObject

               •   -C

                   (     ,          ,
                   ,          )

               •         NSObject
                               .
•   NSLog : C   printf                , stdout
                   stderr               . NSString


               •   NSString    @”          ”                    .

               •   NSLog


               •   NSLog(@”Make %@”, make);
Scope of Instance Variables
               Directive
               Meaning
               @private
               The instance variable is accessible only within the class that declares it.


               @protected
               The instance variable is accessible within the class that declares it and within                                  .
               classes that inherit it.
                All instance variables without an explicit scope directive have @protected        @interface Worker : NSObject
               scope.
                                                                                                  {
               @public
                                                                                                      char *name;
               The instance variable is accessible everywhere.
                                                                                                  @private

               @package                                                                               int age;
               Using the modern runtime, an @package instance variable has @public scope
               inside the executable image that implements the class, but acts like @private          char *evaluation;
               outside.
                                                                                                  @protected
               The @package scope for Objective-C instance variables is analogous to
               private_extern for C variables and functions.                                          id job;
               Any code outside the class implementation’s image that tries to use the
               instance variable gets a link error.                                                   float wage;
               This scope is most useful for instance variables in framework classes, where
                                                                                                  @public
               @private may be too restrictive but @protected or @public too permissive.
                                                                                                      id boss;

                                                                                                  }

                                                                                                  protected: name, job, wage
                                                                                                  private: age, evaluation
                                                                                                  public: boss
•
               •
               •   @property(attributes) type name;

               •   attributes : assign, retain, copy

               •   retain, copy : release message sent to the previous
                   value

               •   attributes: readonly, readwrite(       readwrite)

               •   attribute : nonatomic (default is atomic)
dot syntax
               •            .            =

               •                                       .
                                                 ,
                                         .

               •   property-synthesize
                                             .

               •                     retain, release
retained property
               • property (retain) NSArray *colors;
               • @synthesize colors;
               •
                                                            .

               • self.colors = [NSArray arrayWithObjects:
                 @”Gray”, @”Silver”, @”Black”];
•                                     retain
                   count       1
                                   1                     0
                                           dealloc
                                       .

               •
                           .
•    alloc init
                                   1        .

                -(void) leakyMethod
                {
                    NSArray *array = [[NSArray alloc] init];
                }
                -(void) properMethod
                {
                    NSArray *array = [[NSArray alloc] init];
                    [array release];
                }
                 -(void) anotherProperMethod
                 {
                     NSArray *array = [[[NSArray alloc] init] autorelease];
                     }
               -(void) yetAnotherProperMethod
               {
                   NSArray *array = [NSArray array]; //                       .
                   }
•                             release


               • Car *car = [[[Car alloc] init] autorelease]
               • Car *car = [Car car];
               •   + (Car *) car
                   {
                                                        class method, convenience method

                      return [[[Car alloc] init] autorelease];
                   }
•
               •
               •
                   1   .
• property        retain


               • @property (retain) NSArray *colors
               •
Retain Count
                 When you create an object, it has a retain
                 count of 1.
               • When you send an object a retain
                 message, its retain count is incremented by
                 1.
               • When you send an object a release
                 message, its retain count is decremented by
                 1.
               • When you send an object a autorelease
                 message, its retain count is decremented by
                 1 at some stage in the future.
Autorelease

               •              release
                   release

               • release pool           autorelease
                         release pool
                   release

               •
•
               •
               •                                                                  .

               •
                   •   To declare methods that others are expected to implement

                   •   To declare the interface to an object while concealing its class

                   •   To capture similarities among classes that are not hierarchically related
protocol
               protocol_A.h

               #import <Foundation/Foundation.h>

               @protocol Protocol_A
                - methodA;
                @required
                  - methodB;
                @optional
                  - methodC;
               @end
Toy.h
               #import “protocol_A.h”

               @interface Toy:NSObject <protocol_A>
               {
                 NSString * name;
               }
               @end
Toy.m
               #import “protocol_A.h”

               @implementation Toy
               - method_A
               {
                 printf(“method_A implemented in Toyn”);
               }
               - method_B
               {
                 printf(“method_B implemented in Toyn”);

               }
               @end
main.m
               #import <Foundation/Foundation.h>
               #import “Toy.h”

               main()
               {
                 Toy *toy_object = [[Toy alloc] init];
                 [toy_object method_A];
                 [toy_object method_B];

                   [toy_object release];
               }
•
               •                .

               •                                         .

               •                (.h)     (.m)                .

               •   +   .h           +           .m

               •            +           .m           .
•                          ,

               •   Subclass

               •                              .
                              .

                   -              ,


                   -

                   -

                   -                  .

                   -                              .
ClassName+CategoryName.h

               #import "ClassName.h"



               @interface ClassName ( CategoryName )

               // method declarations

               @end
ClassName+CategoryName.m

               #import "ClassName+CategoryName.h"



               @implementation ClassName ( CategoryName )

               // method definitions

               @end
main.m
               main()
               {
                 Toy * toy_object = [[Toy alloc] init];
                 [toy_object method1];
               }
•
               •
               •
Delegate
               •
               •
               •
               •
•   :


               •

               •
               •
               •

               •
•

               •   -(void)forwardInvocation:(NSInvocation *)anInvocation

               •   NSIvocation

               •   -(SEL)selector :                              .

               •   -(id)target :                             .

               •   -(void) invokeWithTarget:(id)anObject :
NSInvocation
               An NSInvocation is an Objective-C message rendered static, that is, it is an action
               turned into an object. NSInvocation objects are used to store and forward messages
               between objects and between applications, primarily by NSTimer objects and the
               distributed objects system.

               An NSInvocation object contains all the elements of an Objective-C message: a target, a
               selector, arguments, and the return value. Each of these elements can be set directly, and
               the return value is set automatically when the NSInvocation object is dispatched.

               An NSInvocation object can be repeatedly dispatched to different targets; its arguments
               can be modified between dispatch for varying results; even its selector can be changed to
               another with the same method signature (argument and return types). This flexibility
               makes NSInvocation useful for repeating messages with many arguments and
               variations; rather than retyping a slightly different expression for each message, you
               modify the NSInvocation object as needed each time before dispatching it to a new
               target.

               NSInvocation does not support invocations of methods with either variable numbers of
               arguments or union arguments. You should use the invocationWithMethodSignature:
               class method to create NSInvocation objects; you should not create these objects using
               alloc and init.

               This class does not retain the arguments for the contained invocation by default. If those
               objects might disappear between the time you create your instance of NSInvocation and
               the time you use it, you should explicitly retain the objects yourself or invoke the
               retainArguments method to have the invocation object retain them itself.

               Note: NSInvocation conforms to the NSCoding protocol, but only supports coding by an
               NSPortCoder. NSInvocation does not support archiving.
Tasks
               Creating NSInvocation Objects
                1    + invocationWithMethodSignature:
               Configuring an Invocation Object
                1    – setSelector:
                2    – selector
                3    – setTarget:
                4    – target
                5    – setArgument:atIndex:
                6    – getArgument:atIndex:
                7    – argumentsRetained
                8    – retainArguments
                9    – setReturnValue:
                10   – getReturnValue:
               Dispatching an Invocation
                1    – invoke
                2    – invokeWithTarget:
               Getting the Method Signature
                1    – methodSignature
Foundation
                   : mutable
                   : immutable




                                     NSArray              NSMutableArray

                                      NSData               NSMutableData

                                    NSDictionay         NSMutableDictionary

                                       NSSet                NSMutableSet

                                     NSString             NSMutableString

                                 NSAttributedString   NSMutableAttributedString

                                  NSCharaterSet        NSMutableCharacterSet

                                    NSIndexSet           NSMutableIndexSet
•                                           “”                @
                     .

               •   NSString *myname =@”jin seok song”;

               •   NSString *work = [@”Name: “ stringByAppendingString: myname];

               •   #define Manufacturer @”BrainLab, Inc.”

               •                                                    .

               •                                                                   .
NSString


               •
               •       Unicode   .
NSString method
               -
               +(id) stringWithFormat: (NSString *) format, ...;

                 )
               NSString *height;
               height = [NSString stringWithFormat: @”Your height is %d feet, %d inches”, 5, 11];

               -                  (                   )
               - (unsigned int) length;
                  )
               unsigned int length = [height length];
               NSLog(@”height’s length =%d”, length);

               -
               - (BOOL) isEqualToString: (NSString *) aString;

                  )
               NSString *thing1 = @”hello 5”;
               NSString *thing2;
               thing2 = [NSString stringWithFormat:@”hello %d”, 5];

               if([thing1 isEqualToString: thing2])
               {
                    NSLog(@”They are the same!”);
                    }
?

               - (BOOL) hasPrefix: (NSString *) aString;
               - (BOOL) hasSuffix: (NSString *) aString;

                   )
               NSString *filename = @”draft-chapter.pages”;
               if([filename hasPrefix:@”draft”])
               {
                     NSLog(@”It has draft word”);
               }



               NSMutableString class                                .
               MSMutableString
               + (id) stringWithCapacity: (unsigned) capacity;

                  )
               NSMutableString *string;
               string = [NSMutableString stringWithCapacity: 42];


               - (void) appendingString: (NSString *) aString;
               - (void) appendFormat: format,...;

                  )
               NSMutableString *string;
               string = [NSMutableString stringWithCapacity: 50];
               [string appendString: @”Hello there “];
               [string appendFormat: @”human %d!’, 39];
               NSLog(“@% “, string);
NSArray :
               NSDictionary :                     pair
               NSSet:

               NSArray
               - int, float, enum, struct
               - nil
                  )
               NSArray *array;
               array = [NSArray arrayWithObjects: @”one”, @”two”, @”three”, nil];

               - (unsigned) count;
               - (id) objectAtIndex: (unsigned int) index;

                  )
               int i;
               for (i = 0; i < [array count]; i++)
               {
                  NSLog(@”index %d has %@.”, i, [array objectAtIndex: i]);
               }
NSDictionary

               + (id) dictionaryWithObjectsAndKey: (id) firstObject, ...;

               Toy *t1 = [Toy new];
               Toy *t2 = [Toy new];
               Toy *t3 = [Toy new];
               Toy *t4 = [Toy new];

               NSDictionary *toyshop;

               toyshop = [NSDictionary dictionaryWithObjectsAndKeys:
               t1, @”bear”, t2, @”lego”, t3, @”tank”, t4, @”barbie”, nil];

               NSDictionary
               - (id) objectForKey: (id) aKey;
               Toy *toy = [toyshop objectForKey: @”lego”];
NSMutableDictionary
               +(id) dictionaryWithCapacity: (unsigned int)numItems;


               - (void) setObject : (id) anObject forKey : (id) aKey;



               - (void) removeObjectForKey: (id) aKey;

               [toyshop removeObjectForKey: @”barbie”];

Weitere ähnliche Inhalte

Was ist angesagt?

Google app engine cheat sheet
Google app engine cheat sheetGoogle app engine cheat sheet
Google app engine cheat sheetPiyush Mittal
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utilsroxlu
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptecker
 
Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performanceDuoyi Wu
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)jeffz
 
Functional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsFunctional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsAlexander Granin
 
Understanding Javascript Engines
Understanding Javascript Engines Understanding Javascript Engines
Understanding Javascript Engines Parashuram N
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Alexander Granin
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架jeffz
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptMichael Girouard
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)Yeshwanth Kumar
 
Swift as an OOP Language
Swift as an OOP LanguageSwift as an OOP Language
Swift as an OOP LanguageAhmed Ali
 
Jscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScriptJscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScriptjeffz
 

Was ist angesagt? (17)

Google app engine cheat sheet
Google app engine cheat sheetGoogle app engine cheat sheet
Google app engine cheat sheet
 
I os 04
I os 04I os 04
I os 04
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScript
 
Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performance
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
 
V8
V8V8
V8
 
Functional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsFunctional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonads
 
Understanding Javascript Engines
Understanding Javascript Engines Understanding Javascript Engines
Understanding Javascript Engines
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
Swift as an OOP Language
Swift as an OOP LanguageSwift as an OOP Language
Swift as an OOP Language
 
March2004-CPerlRun
March2004-CPerlRunMarch2004-CPerlRun
March2004-CPerlRun
 
Core concepts-javascript
Core concepts-javascriptCore concepts-javascript
Core concepts-javascript
 
Jscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScriptJscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScript
 

Andere mochten auch

Versiones biblicas de la biblia
Versiones biblicas de la bibliaVersiones biblicas de la biblia
Versiones biblicas de la bibliaSilverWolf Aliaga
 
Dewalt dw682 k biscuit joiner- joiner manual
Dewalt dw682 k  biscuit joiner- joiner manualDewalt dw682 k  biscuit joiner- joiner manual
Dewalt dw682 k biscuit joiner- joiner manualNhư Bình
 
Signs to Get Going with Business Intelligence
Signs to Get Going with Business IntelligenceSigns to Get Going with Business Intelligence
Signs to Get Going with Business IntelligenceSPEC INDIA
 
AFORD Presentation to Development Stakeholders In Singida 1
AFORD Presentation to Development Stakeholders In Singida 1AFORD Presentation to Development Stakeholders In Singida 1
AFORD Presentation to Development Stakeholders In Singida 1JOSEPHINE LEMOYAN
 
March '15 College Campus Food Pantry Research Proposal
March '15 College Campus Food Pantry Research ProposalMarch '15 College Campus Food Pantry Research Proposal
March '15 College Campus Food Pantry Research ProposalDerek Field
 
Chernobyl Disaster 1986 PPT By Gokul V Mahajan.
Chernobyl Disaster 1986 PPT By Gokul V Mahajan.Chernobyl Disaster 1986 PPT By Gokul V Mahajan.
Chernobyl Disaster 1986 PPT By Gokul V Mahajan.Gokul Mahajan
 
Environmental Impact Assessment
Environmental Impact AssessmentEnvironmental Impact Assessment
Environmental Impact AssessmentShyam Bajpai
 

Andere mochten auch (15)

Planta
PlantaPlanta
Planta
 
Versiones biblicas de la biblia
Versiones biblicas de la bibliaVersiones biblicas de la biblia
Versiones biblicas de la biblia
 
Dewalt dw682 k biscuit joiner- joiner manual
Dewalt dw682 k  biscuit joiner- joiner manualDewalt dw682 k  biscuit joiner- joiner manual
Dewalt dw682 k biscuit joiner- joiner manual
 
Signs to Get Going with Business Intelligence
Signs to Get Going with Business IntelligenceSigns to Get Going with Business Intelligence
Signs to Get Going with Business Intelligence
 
Bioterio jtl
Bioterio jtlBioterio jtl
Bioterio jtl
 
Florence
FlorenceFlorence
Florence
 
AFORD Presentation to Development Stakeholders In Singida 1
AFORD Presentation to Development Stakeholders In Singida 1AFORD Presentation to Development Stakeholders In Singida 1
AFORD Presentation to Development Stakeholders In Singida 1
 
March '15 College Campus Food Pantry Research Proposal
March '15 College Campus Food Pantry Research ProposalMarch '15 College Campus Food Pantry Research Proposal
March '15 College Campus Food Pantry Research Proposal
 
Inspiring the Next Generation by Dr Mervyn Jones, WRAP
Inspiring the Next Generation by Dr Mervyn Jones, WRAPInspiring the Next Generation by Dr Mervyn Jones, WRAP
Inspiring the Next Generation by Dr Mervyn Jones, WRAP
 
Pre-Sales the Backbone of Sales Force Automation Solutions
Pre-Sales the Backbone of Sales Force Automation SolutionsPre-Sales the Backbone of Sales Force Automation Solutions
Pre-Sales the Backbone of Sales Force Automation Solutions
 
Sales Force Automation for Whole Sale Distributors – A Critical Link in the C...
Sales Force Automation for Whole Sale Distributors – A Critical Link in the C...Sales Force Automation for Whole Sale Distributors – A Critical Link in the C...
Sales Force Automation for Whole Sale Distributors – A Critical Link in the C...
 
それPerlでできるよ
それPerlでできるよそれPerlでできるよ
それPerlでできるよ
 
Gawadar port
Gawadar portGawadar port
Gawadar port
 
Chernobyl Disaster 1986 PPT By Gokul V Mahajan.
Chernobyl Disaster 1986 PPT By Gokul V Mahajan.Chernobyl Disaster 1986 PPT By Gokul V Mahajan.
Chernobyl Disaster 1986 PPT By Gokul V Mahajan.
 
Environmental Impact Assessment
Environmental Impact AssessmentEnvironmental Impact Assessment
Environmental Impact Assessment
 

Ähnlich wie 오브젝트C(pdf)

Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C SurvivesS Akai
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and PointersMichael Heron
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev introVonbo
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone developmentVonbo
 
Mtl LT
Mtl LTMtl LT
Mtl LTaknEp
 
Information from pixels
Information from pixelsInformation from pixels
Information from pixelsDave Snowdon
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-CKazunobu Tasaka
 
constructorsfjy5ediykEASFul;IUWORHusi;gfb.pptx
constructorsfjy5ediykEASFul;IUWORHusi;gfb.pptxconstructorsfjy5ediykEASFul;IUWORHusi;gfb.pptx
constructorsfjy5ediykEASFul;IUWORHusi;gfb.pptxAshrithaRokkam
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたTaro Matsuzawa
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CDataArt
 
webプログラマが楽にiPhoneアプリを開発する方法
webプログラマが楽にiPhoneアプリを開発する方法webプログラマが楽にiPhoneアプリを開発する方法
webプログラマが楽にiPhoneアプリを開発する方法Junya Ishihara
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Yuichi Higuchi
 
Modernizes your objective C - Oliviero
Modernizes your objective C - OlivieroModernizes your objective C - Oliviero
Modernizes your objective C - OlivieroCodemotion
 
Haxe for Flash Platform developer
Haxe for Flash Platform developerHaxe for Flash Platform developer
Haxe for Flash Platform developermatterhaxe
 

Ähnlich wie 오브젝트C(pdf) (20)

Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev intro
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone development
 
Java
JavaJava
Java
 
Mtl LT
Mtl LTMtl LT
Mtl LT
 
Information from pixels
Information from pixelsInformation from pixels
Information from pixels
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
 
constructorsfjy5ediykEASFul;IUWORHusi;gfb.pptx
constructorsfjy5ediykEASFul;IUWORHusi;gfb.pptxconstructorsfjy5ediykEASFul;IUWORHusi;gfb.pptx
constructorsfjy5ediykEASFul;IUWORHusi;gfb.pptx
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Coding for
Coding for Coding for
Coding for
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 
webプログラマが楽にiPhoneアプリを開発する方法
webプログラマが楽にiPhoneアプリを開発する方法webプログラマが楽にiPhoneアプリを開発する方法
webプログラマが楽にiPhoneアプリを開発する方法
 
Objective c
Objective cObjective c
Objective c
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例
 
Modernizes your objective C - Oliviero
Modernizes your objective C - OlivieroModernizes your objective C - Oliviero
Modernizes your objective C - Oliviero
 
Core animation
Core animationCore animation
Core animation
 
Haxe for Flash Platform developer
Haxe for Flash Platform developerHaxe for Flash Platform developer
Haxe for Flash Platform developer
 

Mehr von sunwooindia

아이폰강의(7) pdf
아이폰강의(7) pdf아이폰강의(7) pdf
아이폰강의(7) pdfsunwooindia
 
아이폰강의(6) pdf
아이폰강의(6) pdf아이폰강의(6) pdf
아이폰강의(6) pdfsunwooindia
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서sunwooindia
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서sunwooindia
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서sunwooindia
 
아이폰강의(5) pdf
아이폰강의(5) pdf아이폰강의(5) pdf
아이폰강의(5) pdfsunwooindia
 
아이폰강의(4) pdf
아이폰강의(4) pdf아이폰강의(4) pdf
아이폰강의(4) pdfsunwooindia
 
아이폰강의(3)
아이폰강의(3)아이폰강의(3)
아이폰강의(3)sunwooindia
 
아이폰프로그래밍(2)
아이폰프로그래밍(2)아이폰프로그래밍(2)
아이폰프로그래밍(2)sunwooindia
 

Mehr von sunwooindia (9)

아이폰강의(7) pdf
아이폰강의(7) pdf아이폰강의(7) pdf
아이폰강의(7) pdf
 
아이폰강의(6) pdf
아이폰강의(6) pdf아이폰강의(6) pdf
아이폰강의(6) pdf
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서
 
2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서2011년 상반기 스마트폰이용실태조사 요약보고서
2011년 상반기 스마트폰이용실태조사 요약보고서
 
아이폰강의(5) pdf
아이폰강의(5) pdf아이폰강의(5) pdf
아이폰강의(5) pdf
 
아이폰강의(4) pdf
아이폰강의(4) pdf아이폰강의(4) pdf
아이폰강의(4) pdf
 
아이폰강의(3)
아이폰강의(3)아이폰강의(3)
아이폰강의(3)
 
아이폰프로그래밍(2)
아이폰프로그래밍(2)아이폰프로그래밍(2)
아이폰프로그래밍(2)
 

Kürzlich hochgeladen

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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 
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
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
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
 
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
 

Kürzlich hochgeladen (20)

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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
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
 
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
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
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
 
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
 

오브젝트C(pdf)

  • 1. Object C Bit Academy
  • 2.
  • 3. Object C • C 80 Brad J. Cox • 1980 NextStep • Object C
  • 4. : ( , ) • :
  • 5. • 0 • . • Car *myCar = [[Car alloc] init];
  • 6. : alloc (call retain) • : release • Car *myCar = [[Car alloc] init]; • printf(“The retain count is %dn”, [myCar retainCount]); • [myCar release]; • printf(“Retain count is now %dn”, [myCar retainCount]); //error • , retain release
  • 7. , , • : • : • : • : initWithName: andModel: andYear: ( )
  • 8. • .
  • 9. .h • - • + • .m
  • 10. • .m ( ) #import “Car.h” @implementation Car -(id) init The init method defined in the NSObject class does no initialization, it simply returns self { self = [super init]; if(!self) = return nil; make = nil; model = nil; year = 1901; return self; }
  • 11. [obj method_name]; obj : method_name .
  • 12. + . +(NSString *) motto; • [ _ _ ] • • • •
  • 13. + (NSString *) motto { return (@”Ford Prefects are Mostly Harmless”); } [Car motto]; . [UIApplication sharedApplication]; [UIDevice currentDevice]; [[NSArray alloc] init]; [NSArray array]; -> .
  • 14. • C • -C factory, factory method • . • • NSObject class .
  • 15. alloc class
  • 16. + • •
  • 17. -C static • • ,
  • 18. for/in for loop NSArray *colors = [NSArray arrayWithObjects:@”Blacks”, @”Silver”, @”Gray”, nil]; for (NSString *color in colors) { printf(“Consider buying a %s car”, [color UTF8String]); }
  • 19. NSObject NSArray NSString UIResponder UIView UILabel UIControl UITextField UISlider object C . . .
  • 20. NSObject • -C ( , , , ) • NSObject .
  • 21.
  • 22. NSLog : C printf , stdout stderr . NSString • NSString @” ” . • NSLog • NSLog(@”Make %@”, make);
  • 23. Scope of Instance Variables Directive Meaning @private The instance variable is accessible only within the class that declares it. @protected The instance variable is accessible within the class that declares it and within . classes that inherit it. All instance variables without an explicit scope directive have @protected @interface Worker : NSObject scope. { @public char *name; The instance variable is accessible everywhere. @private @package int age; Using the modern runtime, an @package instance variable has @public scope inside the executable image that implements the class, but acts like @private char *evaluation; outside. @protected The @package scope for Objective-C instance variables is analogous to private_extern for C variables and functions. id job; Any code outside the class implementation’s image that tries to use the instance variable gets a link error. float wage; This scope is most useful for instance variables in framework classes, where @public @private may be too restrictive but @protected or @public too permissive. id boss; } protected: name, job, wage private: age, evaluation public: boss
  • 24. • • @property(attributes) type name; • attributes : assign, retain, copy • retain, copy : release message sent to the previous value • attributes: readonly, readwrite( readwrite) • attribute : nonatomic (default is atomic)
  • 25. dot syntax • . = • . , . • property-synthesize . • retain, release
  • 26. retained property • property (retain) NSArray *colors; • @synthesize colors; • . • self.colors = [NSArray arrayWithObjects: @”Gray”, @”Silver”, @”Black”];
  • 27. retain count 1 1 0 dealloc . • .
  • 28. alloc init 1 . -(void) leakyMethod { NSArray *array = [[NSArray alloc] init]; } -(void) properMethod { NSArray *array = [[NSArray alloc] init]; [array release]; } -(void) anotherProperMethod { NSArray *array = [[[NSArray alloc] init] autorelease]; } -(void) yetAnotherProperMethod { NSArray *array = [NSArray array]; // . }
  • 29. release • Car *car = [[[Car alloc] init] autorelease] • Car *car = [Car car]; • + (Car *) car { class method, convenience method return [[[Car alloc] init] autorelease]; }
  • 30. • • 1 .
  • 31. • property retain • @property (retain) NSArray *colors •
  • 32. Retain Count When you create an object, it has a retain count of 1. • When you send an object a retain message, its retain count is incremented by 1. • When you send an object a release message, its retain count is decremented by 1. • When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future.
  • 33. Autorelease • release release • release pool autorelease release pool release •
  • 34. • • . • • To declare methods that others are expected to implement • To declare the interface to an object while concealing its class • To capture similarities among classes that are not hierarchically related
  • 35. protocol protocol_A.h #import <Foundation/Foundation.h> @protocol Protocol_A - methodA; @required - methodB; @optional - methodC; @end
  • 36. Toy.h #import “protocol_A.h” @interface Toy:NSObject <protocol_A> { NSString * name; } @end
  • 37. Toy.m #import “protocol_A.h” @implementation Toy - method_A { printf(“method_A implemented in Toyn”); } - method_B { printf(“method_B implemented in Toyn”); } @end
  • 38. main.m #import <Foundation/Foundation.h> #import “Toy.h” main() { Toy *toy_object = [[Toy alloc] init]; [toy_object method_A]; [toy_object method_B]; [toy_object release]; }
  • 39. • . • . • (.h) (.m) . • + .h + .m • + .m .
  • 40. , • Subclass • . . - , - - - . - .
  • 41. ClassName+CategoryName.h #import "ClassName.h" @interface ClassName ( CategoryName ) // method declarations @end
  • 42. ClassName+CategoryName.m #import "ClassName+CategoryName.h" @implementation ClassName ( CategoryName ) // method definitions @end
  • 43. main.m main() { Toy * toy_object = [[Toy alloc] init]; [toy_object method1]; }
  • 44. • •
  • 45. Delegate • • • •
  • 46. : • • • • •
  • 47. • -(void)forwardInvocation:(NSInvocation *)anInvocation • NSIvocation • -(SEL)selector : . • -(id)target : . • -(void) invokeWithTarget:(id)anObject :
  • 48. NSInvocation An NSInvocation is an Objective-C message rendered static, that is, it is an action turned into an object. NSInvocation objects are used to store and forward messages between objects and between applications, primarily by NSTimer objects and the distributed objects system. An NSInvocation object contains all the elements of an Objective-C message: a target, a selector, arguments, and the return value. Each of these elements can be set directly, and the return value is set automatically when the NSInvocation object is dispatched. An NSInvocation object can be repeatedly dispatched to different targets; its arguments can be modified between dispatch for varying results; even its selector can be changed to another with the same method signature (argument and return types). This flexibility makes NSInvocation useful for repeating messages with many arguments and variations; rather than retyping a slightly different expression for each message, you modify the NSInvocation object as needed each time before dispatching it to a new target. NSInvocation does not support invocations of methods with either variable numbers of arguments or union arguments. You should use the invocationWithMethodSignature: class method to create NSInvocation objects; you should not create these objects using alloc and init. This class does not retain the arguments for the contained invocation by default. If those objects might disappear between the time you create your instance of NSInvocation and the time you use it, you should explicitly retain the objects yourself or invoke the retainArguments method to have the invocation object retain them itself. Note: NSInvocation conforms to the NSCoding protocol, but only supports coding by an NSPortCoder. NSInvocation does not support archiving.
  • 49. Tasks Creating NSInvocation Objects 1 + invocationWithMethodSignature: Configuring an Invocation Object 1 – setSelector: 2 – selector 3 – setTarget: 4 – target 5 – setArgument:atIndex: 6 – getArgument:atIndex: 7 – argumentsRetained 8 – retainArguments 9 – setReturnValue: 10 – getReturnValue: Dispatching an Invocation 1 – invoke 2 – invokeWithTarget: Getting the Method Signature 1 – methodSignature
  • 50. Foundation : mutable : immutable NSArray NSMutableArray NSData NSMutableData NSDictionay NSMutableDictionary NSSet NSMutableSet NSString NSMutableString NSAttributedString NSMutableAttributedString NSCharaterSet NSMutableCharacterSet NSIndexSet NSMutableIndexSet
  • 51. “” @ . • NSString *myname =@”jin seok song”; • NSString *work = [@”Name: “ stringByAppendingString: myname]; • #define Manufacturer @”BrainLab, Inc.” • . • .
  • 52. NSString • • Unicode .
  • 53. NSString method - +(id) stringWithFormat: (NSString *) format, ...; ) NSString *height; height = [NSString stringWithFormat: @”Your height is %d feet, %d inches”, 5, 11]; - ( ) - (unsigned int) length; ) unsigned int length = [height length]; NSLog(@”height’s length =%d”, length); - - (BOOL) isEqualToString: (NSString *) aString; ) NSString *thing1 = @”hello 5”; NSString *thing2; thing2 = [NSString stringWithFormat:@”hello %d”, 5]; if([thing1 isEqualToString: thing2]) { NSLog(@”They are the same!”); }
  • 54. ? - (BOOL) hasPrefix: (NSString *) aString; - (BOOL) hasSuffix: (NSString *) aString; ) NSString *filename = @”draft-chapter.pages”; if([filename hasPrefix:@”draft”]) { NSLog(@”It has draft word”); } NSMutableString class . MSMutableString + (id) stringWithCapacity: (unsigned) capacity; ) NSMutableString *string; string = [NSMutableString stringWithCapacity: 42]; - (void) appendingString: (NSString *) aString; - (void) appendFormat: format,...; ) NSMutableString *string; string = [NSMutableString stringWithCapacity: 50]; [string appendString: @”Hello there “]; [string appendFormat: @”human %d!’, 39]; NSLog(“@% “, string);
  • 55. NSArray : NSDictionary : pair NSSet: NSArray - int, float, enum, struct - nil ) NSArray *array; array = [NSArray arrayWithObjects: @”one”, @”two”, @”three”, nil]; - (unsigned) count; - (id) objectAtIndex: (unsigned int) index; ) int i; for (i = 0; i < [array count]; i++) { NSLog(@”index %d has %@.”, i, [array objectAtIndex: i]); }
  • 56. NSDictionary + (id) dictionaryWithObjectsAndKey: (id) firstObject, ...; Toy *t1 = [Toy new]; Toy *t2 = [Toy new]; Toy *t3 = [Toy new]; Toy *t4 = [Toy new]; NSDictionary *toyshop; toyshop = [NSDictionary dictionaryWithObjectsAndKeys: t1, @”bear”, t2, @”lego”, t3, @”tank”, t4, @”barbie”, nil]; NSDictionary - (id) objectForKey: (id) aKey; Toy *toy = [toyshop objectForKey: @”lego”];
  • 57. NSMutableDictionary +(id) dictionaryWithCapacity: (unsigned int)numItems; - (void) setObject : (id) anObject forKey : (id) aKey; - (void) removeObjectForKey: (id) aKey; [toyshop removeObjectForKey: @”barbie”];