I have this code in Swift:
guard let user = username else{
return nil
}
But I'm getting the following errors:
Nil is incompatible with return type String
Any of you knows why or how I return nil in this case?
I'll really appreciate your help
you have to tell the compiler that you want to return nil. How do you that? by assigning '?' after your object. For instance take a look at this code:
Notice that i had to tell the compiler that my Object Friend that i'm returning is an optional 'Friend?' other wise it spill an error on me
Does your function declare an optional return type?
func foo() -> String? { ...
See more on: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html