I am starting out with swift am trying to keep my code concise.
I have a custom init method
var title, initMainText, initBtnTitle: String?
...
init(title: String?, mainText: String?, buttonTitle: String?) {
if let t = title {
self.title = t
}
if let t = mainText {
self.initMainText = t
}
if let t = buttonTitle {
self.initBtnTitle = t
}
...
}
...
Is there a more concise way to unwrap all those conditionals?
guardagainstnilwhen they are "used".self.titleis an optional is a guess because your vague question doesn't include the declaration of the variable. That someone made guesses at a good answer for your question does not make your question good.