问题
I have,
struct S {}
Along with,
func y (x: S) -> AnyObject {}
In Swift 2, is it possible to, within y(),
return x
My current code:
struct S {let value: Int = 0}
let x = S()
func y(x: S) -> AnyObject {return x}
Yields the following error:
return expression of type 'S' does not conform to type 'AnyObject'
Is there a way to mitigate this?
回答1:
A Struct
cannot conform to AnyObject
. It can only conform to Any
来源:https://stackoverflow.com/questions/33921907/how-to-cast-a-struct-to-anyobject-in-swift-2