Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Objective c(lang)

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
Writing Groovy DSLs
Writing Groovy DSLs
Chargement dans…3
×

Consultez-les par la suite

1 sur 18 Publicité

Plus De Contenu Connexe

Les utilisateurs ont également aimé (18)

Publicité

Similaire à Objective c(lang) (20)

Publicité

Plus récents (20)

Objective c(lang)

  1. 1. Objective C Part 1 Language
  2. 2. Overview NeXTSTEP Smalltalk https://www.youtube.com/watch?v=j02b8Fuz73A
  3. 3. Language Design Static and Strongly Typed Keyword No GC (ARC) Superset of C (works as C compiler) Not method but message Protocol & Delegate Category
  4. 4. Hello World NSLog(@“Hello World”); Interpolation %@
  5. 5. Types C types int, char, float, const, unsigned Objective C NSObject, NSString, NSNumber, NSArray, NSDictionary NSMutableArray id
  6. 6. Methods [Messages] obj.method(param); [obj message:param]; [obj sayHello:@“Hello!”];
  7. 7. Methods [Messages] obj.method(param1, param2); [obj message:param1, keyword2:param2] [person setFirst:@“John” setLast:@“Doe” setAge:@34] The message signature is setFirst:setLast:setAge:
  8. 8. - (void) sayHello: (NSString *) param { NSLog(@“Hello %@ World”, param); }; - (String) sayHello:(Type)param1 keyword2:(Type)param2 keyword3:(Type)param3 {}; Methods [Messages] @Implementation
  9. 9. List and Dictionary NSArray *list = @[obj1, obj2, obj3, …]; NSDictionary *dict = @{ key:val, key:val}NSDictionary *dict = @{ key:val, key:val}
  10. 10. ^Callback (Block) ^ refers to an anonymous function Define a block called Callback, which takes a NSString, then return void Pass in a block Implement a method called ajax:word: ajax takes a Callback type
  11. 11. Class Person.h Person.m Caller.m #import “Person.h” Person *p = [Person new]; @interface @end @implementation @end - (void) sayHello {…}; - (void) sayHello; [p sayHello]; visible implement
  12. 12. Class Person.h Person.m Caller.m
  13. 13. Selector Reflection in Java SEL method = NSSelectorFromString(@“getFullname”); [obj performSelector:method];
  14. 14. <Protocol> Interface in Java C21Protocol.h
  15. 15. Delegate Pattern Like Java, Protocol is used in Delegate Pattern. But, use of Block is recommended. -doYouKnowObjectiveC <Protocol> Developer.m Manager.mClient Delegate patterns are used in Views and Controllers. I’ll show you the code in the GUI part. - delegate -doYouKnowObjectiveC
  16. 16. Category Extends the existing class (like Ruby’s monkey patch) Person+age.h Person+age.m Caller.m To extend Person, prepare two files called: Person+age.h Person+age.m Add getAge()
  17. 17. Class Extension Class extension is like anonymous Category () Define @interface in a .m file The methods are private scope. They are not visible from outside of the file.
  18. 18. Property Option (avoid memory leak) Button View Controller (weak) btnStrong weak View points to the Button object strongly, while Controller.btn points to the Button weekly. Thus, Compiler (ARC) can delete the Button object when the Strong link is detached. There is no GC in Objective-C. Compiler will insert destructor statements.

×