嘿,我刚开始使用Objective-C,我遇到了嵌套消息传递概念。我不明白我们为什么要使用它以及如何在语法和语义上使用它。
例如:
[[myAppObject theArray] insertObject:[myAppObject objectToInsert] atIndex:0]
这是一个我来到across.My问题是,我不知道是什么[myAppObject theArray]是doing.Is它创建的实例myAppObject还是有一类通过与方法名theArray?
谁能阐明这个话题?
它是创建myAppObject的实例还是通过方法theArray创建具有该名称的类?
两者都不; myAppObject
是类的实例MyAppObject
(假设已使用常规命名),theArray
并且正在向该实例发送消息的实例方法或属性。
所以MyAppObject
看起来像这样:
@interface MyAppObject : NSObject {
NSArray *_theArray; // This is optional, and considered to be old fashioned
// (but not by me).
}
@property (nonatomic, strong) NSArray *theArray;
...
@end
已在以下位置分配了这样的内容:
MyAppObject *myAppObject = [[MyAppObject alloc] init];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句