2011年11月16日 星期三

Stanford CS193p Fall 2011 Note-01

參考: iPad and iPhone Application Development (HD) - Download free content from Stanford on iTunes

MVC:


-----------------------------------------------------------------------------
private methods:

-----------------------------------------------------------------------------
nonatomic:
@property nonatomic means its setter and getter are not thread-safe.
That's no problem if this is UI code because all UI code happens
on the main thread of the application.

-----------------------------------------------------------------------------
synthesize:
ex: @synthesize topSpeed = _topSpeed;

1. We almost always use @synthesize to create the implementation of the setter
   and getter for a @property. It both creates the setter and getter methods AND
   creates some storage to hold the value.

2. _topSpeed
  (1). This is the name of the storage location to use.
  (2). _ (underbar) then the name of the property is a common naming convention.
 
3. If we don't use = here, @synthesize uses the name of the property
   (which is bad so always use =).

4. This is what the methods created by @synthesize would look like:
- (void)setTopSpeed:(double)speed
{
    _topSpeed = speed;
}
- (double)topSpeed
{
    return _topSpeed;
}

-----------------------------------------------------------------------------

private property:
ex:
// in Spaceship.m
@interface Spaceship()
// declaration of private methods (as needed)
@property (nonatomic, strong) Wormhole *nearestWormhole;
@end

@synthesize nearestWormhole = _nearestWormhole;

1. strong:
   It's a pointer to an object (of class Wormhole). It's strong which means that the
   memory used by this object will stay around for as long as we need it.

2. *nearestWormhole:
    All objects are always allocated on the heap. So we always access them through
    a pointer. Always.

3. @synthesize:
    does NOT create storage for the object this pointer points to.
    It just allocates room for the pointer.

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。