Created
September 19, 2017 13:01
-
-
Save Sadmansamee/c2faf3c9187279289577b085822d54c7 to your computer and use it in GitHub Desktop.
It's not null but is it empty?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Optional where Wrapped == String { | |
var nilIfEmpty: String? { | |
guard let strongSelf = self else { | |
return nil | |
} | |
return strongSelf.isEmpty ? nil : strongSelf | |
} | |
}//USAGE | |
//guard let title = textField.text.nilIfEmpty else { | |
// // Alert: textField is empty! | |
// return | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment