SlideShare une entreprise Scribd logo
1  sur  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”];

Contenu connexe

Tendances

Google app engine cheat sheet
Google app engine cheat sheetGoogle app engine cheat sheet
Google app engine cheat sheet
Piyush Mittal
 
Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performance
Duoyi 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
 
Jscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScriptJscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScript
jeffz
 

Tendances (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
 

En vedette

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
JOSEPHINE 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 Proposal
Derek Field
 

En vedette (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
 

Similaire à 오브젝트C(pdf)

Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
S Akai
 
スマートフォン勉強会@関東 #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-C
DataArt
 

Similaire à 오브젝트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
 

Plus de sunwooindia

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

Plus de 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)
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

오브젝트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”];