Thursday, November 17, 2016

Hide status bar

In Swift 3, to hide the status bar, simply add the following to your view controller.
override var prefersStatusBarHidden: Bool {  
    return true  
}  

However, sometimes you might just want to do it in a completion block, or within some animation block. In that case, add
UIApplication.shared.isStatusBarHidden = true
And toggle off when desired

Friday, November 4, 2016

Check optional + empty string together

Apart from checking nil from an optional string, it's pretty common for us to check whether or not that optional as an empty string. e.g: ""

I found this wonderful solution, credits to StackOverflow once more.

(string ?? "").isEmpty

Source: http://stackoverflow.com/questions/29381994/swift-check-string-for-nil-empty