Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Swift中声明符合协议的类_Swift - Fatal编程技术网

在Swift中声明符合协议的类

在Swift中声明符合协议的类,swift,Swift,在objective-C中,我们可以将符合某些协议的类声明为 @property (nonatomic, strong) Class<UIObjectRestoration> objectRestorationClass; 问题是: 我怎样才能用斯威夫特?我试着用 var objectRestorationClass: UIObjectRestoration! 及 但这给了我一个错误 “SomeClass.Type”未转换为协议“UIObjectRestoration” 有些课程

在objective-C中,我们可以将符合某些协议的类声明为

@property (nonatomic, strong) Class<UIObjectRestoration> objectRestorationClass;
问题是: 我怎样才能用斯威夫特?我试着用

var objectRestorationClass: UIObjectRestoration!

但这给了我一个错误

“SomeClass.Type”未转换为协议“UIObjectRestoration”

有些课程是:

class SomeClass: UIViewController, UIObjectRestoration {

 class func objectWithRestorationIdentifierPath(identifierComponents: [AnyObject]!, coder: NSCoder!) -> UIStateRestoring! {

        return restoringObject
    }

}

我尝试键入它,但它给了我相同的错误。

[UIObjectRestoration]
是UIObjectRestoration项的数组。使用
var-objectRestorationClass:UIObjectRestoration
并使用
objectRestorationClass=SomeClass.classForCoder赋值,您可以使用

var objectRestorationClass: UIObjectRestoration.Type!

“AnyClass”与“UIObjectRestoration”不完全相同在Objective-C中使用
Class
与仅使用
Class
之间是否有明显区别?
class SomeClass: UIViewController, UIObjectRestoration {

 class func objectWithRestorationIdentifierPath(identifierComponents: [AnyObject]!, coder: NSCoder!) -> UIStateRestoring! {

        return restoringObject
    }

}
var objectRestorationClass: UIObjectRestoration.Type!