objective-c - 如何将 self 作为方法参数传递?

我需要将 self 传递给方法,我该怎么做?

我不知道 self 是什么类型的对象?

我试过 :(id)dg

最佳答案

当您在类 Foo@implementation block 内时,selfFoo*。这意味着您可以将方法参数键入 Foo*id(= 任何对象,不进行类型检查):

@class Foo, SomeCollaborator;

@interface SomeCollaborator
- (void) doSomethingWithMe: (Foo*) myself;
- (void) doSomethingWithMe2: (id) myself;
@end

@implementation Foo
- (void) someFooMethod {
    [someCollaborator doSomethingWithMe:self];
}
@end

https://stackoverflow.com/questions/4213505/

相关文章:

assembly - 是否有适用于 Windows 的免费小型汇编代码编译器/汇编器?

php - 永久登录

scheme - Racket 中的gensym

delphi - 控件放在最上面,像TPanel 可以吗?

configuration - 在 Windows 中为 gvim 加载 .vimrc 并更改字体和

maven-2 - 为什么 Maven2 在每次构建时检查 stax-ex 的更新?

sql - Informix 7.3 - 声明日期列数据类型,默认为插入/更新时的当前日期

regex - 在正则表达式匹配中检测标量的精确字符串值

macos - 关闭mac的脚本

PHP:哪个更快 - array_sum 还是 foreach?