+ (id)buttonWithType:(UIButtonType)buttonType
class func buttonWithType(buttonType: UIButtonType) -> AnyObject!
调用var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
+ (instancetype)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc
class func stringWithCString(cString: CString, encoding enc: UInt) -> Self!
var str = NSString.stringWithCString("foo", encoding: NSUTF8StringEncoding)
var cs = str.UTF8String
只要object-c返回id类型的 都要在后面加as 这样才能保证类型一致
本文介绍了Objective-C中UIButton和NSString的类型转换方法,包括如何使用buttonWithType创建UIButton实例及如何利用stringWithCString将C字符串转换为NSString。通过具体代码示例展示了确保类型一致性的技巧。
631

被折叠的 条评论
为什么被折叠?



