0

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
Airspeed Velocity
  • 40,491
  • 8
  • 113
  • 118

1 Answers1

6

i've figured out the solution

let firstName = self.currentUser?["firstName"] as? String
if let firstname = firstName {
     // Continue
} else {
    // Handling the error.
}
  • 1
    Beware, by using `!` instead of `?` in those two places, you are running the risk that if `currentUser` is ever `nil`, or if it doesn't have a value for `firstName`, then your app will crash. You might want to consider `if let firstName = self.currentUser?["firstName"] as? String { ...use firstName... } else { ...optionally handle error... }` – Airspeed Velocity Apr 09 '15 at 16:37
  • ok i'll consider, but i my answer is it right if yes please accept it – Mohamed Sneiba Apr 09 '15 at 16:39