devxoul / Then

✨ Super sweet syntactic sugar for Swift initializers
MIT License
4.18k stars 290 forks source link

@discardableResult `then` and `with` #44

Closed iTofu closed 7 years ago

iTofu commented 7 years ago

Sometimes we needn't return value, like this:

UINavigationBar.appearance().then({
    $0.tintColor           = .white
    $0.barTintColor        = .ggTint
    $0.isTranslucent       = true
    $0.titleTextAttributes = [
        NSFontAttributeName: UIFont.systemFont(ofSize: 18.0),
        NSForegroundColorAttributeName: UIColor.white
    ]
})

No @discardableResult will give us a warning says:

Result of call to 'then' is unused

So what we should to do is just add @discardableResult :)

devxoul commented 7 years ago

In this case you can use do() instead.

iTofu commented 7 years ago

Woo, yes, thank you!