@IBOutlet var navBar: UINavigationBar!
@IBOutlet var menuButton: UIBarButtonItem!
@IBOutlet var topicNameLabel: UILabel!
var topicName:String!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
menuButton.target = self.revealViewController()
menuButton.action = Selector("revealToggle:")
navBar.barTintColor = UIColor(red: 0, green: 0.4176, blue: 0.4608, alpha: 1)
topicNameLabel.text = self.topicName
}
That's my code, I will pass a string to the topicName by prepareForSegue, however, I find that in the simulator, my topicNameLabel shows "Optional(The text I want)". I just want the "The text I want", but do not need the Optional. Could any one help me?
topicNameLabel.text = self.topicName ?? "". If you optional variabletopicNameisnil, a default empty text""will be shown, whereas if it's non-nil, the value will be unwrapped and assigned to your label text. Also, you probably want to declare yourStringvariable asvar topicName : String?, rather thanString!.topicNameproperty?""topicNameas non-optional empty string. An "absent" value on a label is an empty string anyway.