iwi*_*ill 8 methods syntax objective-c
声明,实现和使用这样的方法:
Test.h:
- method:parameter;
Run Code Online (Sandbox Code Playgroud)
Test.m:
- method:parameter{
return nil;
}
Run Code Online (Sandbox Code Playgroud)
使用:
[test method:anObject];
Run Code Online (Sandbox Code Playgroud)
没有返回类型和参数类型,但它没有任何警告或错误.有人可以解释一下吗?
小智 12
正如Objective-C编程语言文档所述:
如果未显式声明返回或参数类型,则假定它是方法和消息的默认类型 - an
id.
所以:
- method:parameter;
Run Code Online (Sandbox Code Playgroud)
有效意味着:
- (id)method:(id)parameter;
Run Code Online (Sandbox Code Playgroud)
相应地:
- method:parameter{
return nil;
}
Run Code Online (Sandbox Code Playgroud)
有效意味着:
- (id)method:(id)parameter{
return nil;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
541 次 |
| 最近记录: |