unj2
unj2

Reputation: 53481

Convert AnyObject? to String

I have a function that returns AnyObject?

func aFunction(param:String) -> AnyObject?

How do I cast it to a String? and String

Upvotes: 4

Views: 3432

Answers (1)

rintaro
rintaro

Reputation: 51911

Try this:

if let result = aFunction("test") as? String {
    // Here, `result` is String
    println(result)
}

Upvotes: 8

Related Questions