当你在@implementation一个班级里面时Foo,self是Foo*.这意味着您可以将方法参数键入为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)