目标c中的嵌套方法调用

约翰尼·亨特(Johnnyhunter)

嘿,我刚开始使用Objective-C,我遇到了嵌套消息传递概念。我不明白我们为什么要使用它以及如何在语法和语义上使用它。

例如:

[[myAppObject theArray] insertObject:[myAppObject objectToInsert] atIndex:0]    

这是一个我来到across.My问题是,我不知道是什么[myAppObject theArray]是doing.Is它创建的实例myAppObject还是有一类通过与方法名theArray

谁能阐明这个话题?

Trojanfoe

它是创建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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章