I am studying XCode7.3. The "?" and "!" always make me confused.
I have code like below.
The lines name : name
, type : type
and image : image
displaying error message :
Value of optional type 'String?' not unwrapped, did you mean to use '!' or '?'?
@IBAction func unwindToHomeScreen( segue : UIStoryboardSegue ) {
if let addRestaurantController = segue.sourceViewController as? AddRestaurantController {
let name = addRestaurantController.name
let location = addRestaurantController.location
let type = addRestaurantController.type
let isVisited = addRestaurantController.isVisited
let image = addRestaurantController.imageView
restaurants.append( Restaurant(
name : name,
type : type,
location : location,
phoneNumber : "UNKNOW",
image : image,
isVisited : isVisited? ?? false
) )
print( addRestaurantController.imageView )
}
}
I modify code to name : name!
or name : name?
, it still doesn't work. How can I fix it?