【发布时间】:2014-08-05 11:59:01
【问题描述】:
在 Objective-C 中,我们可以将符合某些协议的类声明为
@property (nonatomic, strong) Class<UIObjectRestoration> objectRestorationClass;
并且可以给它赋值为
someObject.objectRestorationClass = [SomeClass class];
问题是: 我怎样才能在 Swift 中做到这一点?我尝试使用
var objectRestorationClass: UIObjectRestoration!
和
someObject.objectRestorationClass = SomeClass.self
但它给了我错误
“SomeClass.Type”不转换为协议“UIObjectRestoration”
SomeClass 是:
class SomeClass: UIViewController, UIObjectRestoration {
class func objectWithRestorationIdentifierPath(identifierComponents: [AnyObject]!, coder: NSCoder!) -> UIStateRestoring! {
return restoringObject
}
}
我尝试了类型转换,但它给了我同样的错误。
【问题讨论】:
-
在 Objective-C 中使用
Class<UIObjectRestoration>和仅使用Class有什么明显区别吗?
标签: swift