How to cast a struct to Anyobject in Swift 2?

我们两清 提交于 2019-12-12 08:30:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!