[英]Objective-C equivalent to Swift's “Any”
Is there any way that an Objective-C method could operate on primitive parameters without knowing their types?有没有什么方法可以让 Objective-C 方法在不知道类型的情况下对原始参数进行操作? For instance,
例如,
-(Any)returnFirst:(Any)first notSecond:(Any)second {
return first;
}
This could then be used like:然后可以这样使用:
int a = [self returnFirst:500 notSecond:1000];
char b = [self returnFirst:'a' notSecond:'b'];
There is no equivalent to Any
in Objective-C.在 Objective-C 中没有与
Any
等价的东西。 Your example returnFirst:notSecond:
cannot even be declared in Objective-C.您的示例
returnFirst:notSecond:
甚至不能在 Objective-C 中声明。
In Swift 3, the
id
type in Objective-C now maps to theAny
type in Swift, which describes a value of any type, whether a class, enum, struct, or any other Swift type.在 Swift 3 中,Objective-C 中的
id
类型现在映射到 Swift 中的Any
类型,它描述了任何类型的值,无论是类、枚举、结构还是任何其他 Swift 类型。
Source: https://developer.apple.com/swift/blog/?id=39来源: https : //developer.apple.com/swift/blog/?id=39
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.