Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The messy lecture

509 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

The messy lecture

  1. 1. РАЗХВЪРЛЯНАТА ПРЕЗЕНТАЦИЯ Около първи етаж след основитеThursday, December 22, 11
  2. 2. DOT SYNTAX set (.) alternative to ([]) to invoke accessor methods get self.age = 10; // Each member of the path is an object. [self setAge:10]; x = person.address.street.name; x = [[[person address] street] name]; // The path contains a C struct. // This will crash if window is nil or -contentView returns nil. y = window.contentView.bounds.origin.y; y = [[window contentView] bounds].origin.y; // An example of using a setter. person.address.street.name = @"Oxford Road"; [[[person address] street] setName: @"Oxford Road"];Thursday, December 22, 11
  3. 3. CHAPTER 2 Defining a Class INSTANCE VARIABLES SCOPEFigure 2-‐1 illustrates the levels of scoping. Figure 2-1 The scope of instance variables (@package scope not shown) The class that declares the @private instance variable @protected A class that inherits the @public instance variable Unrelated code • default : @protectedThursday, December 22, 11
  4. 4. INSTANCE VARIABLES SCOPE @interface Worker : NSObject { NSString *name; @private NSInteger age; NSString *evaluation; @protected id job; CGFloat wage; @public id boss; }Thursday, December 22, 11
  5. 5. @property @property float value; @property(copy, readwrite) NSString *value; @synthesize = напищи ми getter & setter Access Memory Multithreaded environment (ARC) readwrite - default strong (owning) By default, accessors are atomic. readonly - only the getter method weak (non-owning) nonatomic returns the value directly (MRC) copy The previous value is sent a release message. NSCopying  protocol. assign default. NSInteger, CGRect.... retain upon assignment. The previous value is release-dThursday, December 22, 11
  6. 6. MEMORY MANAGEMENT Защо да създаваме обект: • запазване на instance variable • използване в методThursday, December 22, 11
  7. 7. MEMORY MANAGEMENT Setter method - (void)setLastUpdatedDate:(NSDate *)newDate { ! if (newDate) { ! ! [lastUpdatedDate release]; ! ! lastUpdatedDate = [newDate retain]; } } //Recommended code: -(void) setName: (NSString *) theName {    [name release]    name = [[NSString alloc] initWthString: theName]; } //Incorrect code according to Kochan: -(void) setName: (NSString *) theName {    [name release]    name = [NSString stringWthString: theName]; }Thursday, December 22, 11
  8. 8. MEMORY MANAGEMENT NSNumber* value1 = [[NSNumber alloc] initWithFloat:8.75]; [self setTotal:value1]; NSNumber* value2 = [NSNumber numberWithFloat:14.78]; [self setTotal:value2]; // only release value1 [value1 release];Thursday, December 22, 11
  9. 9. MESSAGES TO NIL [myArray release]; id anObjectMaybeNil = nil; myArray = nil; // this is valid if ([anObjectMaybeNil methodThatReturnsADouble] == 0.0) { // implementation continues... }Thursday, December 22, 11
  10. 10. TTIMAGEVIEW UIImageView Name Link Title Note TTImageViewThursday, December 22, 11
  11. 11. XCODE • NSString • .plist • [NSUserDefaults standardUserDefaults] • Custom UIImageView classThursday, December 22, 11

×