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

Jul*_*les 1 xcode objective-c

我需要将自己传递给一个方法,我该怎么做?

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

我试过了 :(id)dg

zou*_*oul 7

当你在@implementation一个班级里面时Foo,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
Run Code Online (Sandbox Code Playgroud)