Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast a struct to Anyobject in Swift 2?

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?

like image 785
Brandon Bradley Avatar asked Nov 25 '15 16:11

Brandon Bradley


1 Answers

A Struct cannot conform to AnyObject. It can only conform to Any

like image 142
Duncan C Avatar answered Oct 19 '22 19:10

Duncan C