Skip to content

Instantly share code, notes, and snippets.

@Sadmansamee
Created September 19, 2017 13:01
Show Gist options
  • Save Sadmansamee/c2faf3c9187279289577b085822d54c7 to your computer and use it in GitHub Desktop.
Save Sadmansamee/c2faf3c9187279289577b085822d54c7 to your computer and use it in GitHub Desktop.
It's not null but is it empty?
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