第3章 Object c

来源:互联网 发布:搜索引擎快速排名软件 编辑:程序博客网 时间:2024/06/06 16:37

第3章
3.1 basic grammar

object c is a extension of c.
it's basic grammer is that:
[object_receiver message]
ex. [NSMutableArray alloc]
[object_receiver messageparam1:param1 messageparam2:param2]
ex. [x intersectsArcWithRadius:35.0 centeredAtX:19.0 Y:23.0 fromAngle:90.0 toAngle:120.0]
object c string = @"string"

3.2 basic class

NSObject
^
|
|---------------|
NSArray         NSString
^
|
|
NSMutableArray

NSObject:
-(id)init
[[NSObject alloc] init]
-(NSString *)descprition
NSLog(@"the number at index %d is %@", i, object)
-(BOOL)isEqual: (id)anObject
NSMutableArray
mutable means not const, once the object is created, it can be add and remove.

3.3 we should use "uses and knows about" more than "inherit from"

3.4 make lottery class of my own.

1)define a new class, and add the object to the Array. print the array, it is not the way we expect.
2)introduce NSCalendarDate
+(id)calendarDate: + means class method , we can use it as [NSCalendarDate calendarDate]
3)write initializers
(1)basic init
-(id)init
{
[super init];
your methods;
return self;
}

(2)initializers with arguments
-(id)initWithEntryDate: (NSCalendarDate *)theDate
{}
(3)the protect from ignorance, override the basic initialzer
-(id)init
{
return [self initWithEntryDate:[NSCalendarDate calendarDate]];
}

3.5 debug

cocoa application 断点无效, 但是iphone:windows based application 可以。暂时不影响iphone程序的调试。

原创粉丝点击