Out of nothing I got this error Expression type \'@lvalue String?\' is ambiguous without more context in my code:
if textView.text != \"\" &
In the code above,
Use userLabel?.text
directly without unwrapping anything. addedByUser
is of type String?
.
You're using UserImage
type for userImage
parameter. Use a UIImage
instance or nil
instead.
You haven't added data
parameter in your code.
Here is the code,
let newJob = Job(text: textView.text, jobImage: takenImage, addedByUser: userLabel?.text, userImage: nil, location: userLocation.text, passMap: takenLocation, userID: userID, postID: key, data: [:])
Avoid unnecessarily force-unwrap the optionals
. It might result in runtime exception.
Two things are wrong:
textView.text != ""
You are comparing an optional String
with a non-optional one.
Replace by:
if let text = textView.text, text != ""
Then in your constructor, don't unwrap the text!
If you want keep the optional :
self.text = text ?? "" //will avoid crash
Or better:
init(text: String = "")