This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(id)create | |
{ | |
return [[self alloc] init]; | |
} |
[Dog Create];
最後將呼叫定義於Animal裡create method,而此時的self將是Dog類別,因此我們才能順利建出Dog物件,而不是四不像的Animal物件。
關於產生物件的類別method,還有一點值得注意,當牽扯到ARC時,回傳的物件是否由autorelease pool管理,取決於method名稱的開頭。只要method名稱不是以alloc, new, copy開頭時,回傳的物件即由autorelease pool統一管理。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
Song *song = [Song allocByGod]; | |
song = nil; | |
song = [Song createByGod]; | |
song = nil; | |
song = [Song copyByGod]; | |
song = nil; | |
song = [Song newByGod]; | |
song = nil; | |
NSLog(@"viewDidLoad done"); | |
} |
沒有留言:
張貼留言