如何在Swift 2中将结构转换为Anyobject?
问题描述:
我有,
struct S {}
同时,
func y (x: S) -> AnyObject {}
在Swift 2中,是否有可能在y(),
In Swift 2, is it possible to, within y(),
return x
我当前的代码:
struct S {let value: Int = 0}
let x = S()
func y(x: S) -> AnyObject {return x}
产生以下错误:
返回类型'S'的表达式不符合'AnyObject'类型
return expression of type 'S' does not conform to type 'AnyObject'
是有办法缓解这种情况吗?
Is there a way to mitigate this?
答
Struct
无法符合 AnyObject
。它只能符合任何
A Struct
cannot conform to AnyObject
. It can only conform to Any