Here's an extension you can add to the
String class that checks for an empty (after trimming whitespace) or nil string:
extension String {
public static func isNilOrEmpty(string: String?) -> Bool {
switch string?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) {
case .Some(let nonNilString):
return nonNilString.isEmpty
default:
return true
}
}
}
You can use it like this:
var isEmpty = String.isNilOrEmpty(myString)
All the best!
Kevin McNeish
Author of Learn to Code in Swift:
https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11