Mohamed Sneiba
Mohamed Sneiba

Reputation: 91

How to cast AnyObject? to String in Swift 1.2

Everything good until, I've downloaded the new version of Xcode 6.3 and Swift 1.2.

But when I compile my app again, a lots of error came out. I've dealt with most of them but there is a specific error that I couldn't figure it out the solutions

The error is "AnyObject? is not convertible to String?"

Before updating Xcode this was absolutely fine :

let firstName = self.currentUser["firstName"] as? String

Upvotes: 0

Views: 2369

Answers (1)

Mohamed Sneiba
Mohamed Sneiba

Reputation: 91

i've figured out the solution

let firstName = self.currentUser?["firstName"] as? String
if let firstname = firstName {
     // Continue
} else {
    // Handling the error.
}

Upvotes: 6

Related Questions