Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert AnyObject? to String

Tags:

ios

swift

cocoa

I have a function that returns AnyObject?

func aFunction(param:String) -> AnyObject?

How do I cast it to a String? and String

like image 833
unj2 Avatar asked Feb 11 '23 16:02

unj2


1 Answers

Try this:

if let result = aFunction("test") as? String {
    // Here, `result` is String
    println(result)
}
like image 56
rintaro Avatar answered Feb 14 '23 09:02

rintaro