Remove "optional" keyword while displaying string - Swift

3824 views ios
4

I am working on a movies app and it displays release date as part of the movie details on table view cell. Below is the code:

let date = movieDetail.releaseDate as String
let releaseDateText = NSLocalizedString("release date", comment: "Release date label text")
let tbaText = NSLocalizedString("tba", comment: "TBA text")
releaseDateLabel.text = "\(releaseDateText): \(String(describing: date != "" ? Date.getMMMddyyyyDateFormat(date) : "\(tbaText)" ))"

With this, I do see the date on the screen as Optional("Jan 07,2018"). I just want to display the date without optional keyword and parenthesis. Am not able to figure out what is causing "Optional" keyword to show up.

Part of my app: enter image description here

answered question

1 Answer

4

Replace this

releaseDateLabel.text = "\(releaseDateText): \(String(describing: date != "" ? Date.getMMMddyyyyDateFormat(date) : "\(tbaText)" ))"

with

releaseDateLabel.text = "\(releaseDateText): \(date != "" ? Date.getMMMddyyyyDateFormat(date) : "\(tbaText)" ))

posted this

Have an answer?

JD

Please login first before posting an answer.