ios - If - else in Swift -
i can alert show, has problems:
- the title not appear
i can't if statement part work. alert pops showing only:
the message numbers must 24 or less
along close button , never changes.
using xcode 6.3 , ios 8.
var title: string! if difference > hourslabel { title = "sorry!" } else if difference < hourslabel { title = "that's better!" } let message = "number must 24 or less" var alert = uialertcontroller(title: title, message: message, preferredstyle: uialertcontrollerstyle.alert) alert.addaction(uialertaction(title: "close", style: .default, handler: nil)) self .presentviewcontroller(alert, animated: true, completion: nil)
based on provided, seems problem using else if
, rather else
only
solution 1:
var title: string! if difference > hourslabel { title = "sorry!" } else { title = "that's better!" }
solution 2:
let title = (difference > hourslabel) ? "sorry": "that's better!" ;
Comments
Post a Comment