Skip to content

Instantly share code, notes, and snippets.

@azone
Created August 5, 2015 02:12
Show Gist options
  • Save azone/6e120333e725aa639dde to your computer and use it in GitHub Desktop.
Save azone/6e120333e725aa639dde to your computer and use it in GitHub Desktop.
determine the CollectionType or String is nil or empty
public protocol Emptiable {
var isEmpty: Bool { get }
}
extension String: Emptiable {}
extension Optional where T: Emptiable {
public var isNilOrEmpty: Bool {
guard let obj = self else { return true }
return obj.isEmpty
}
}
extension Optional where T: CollectionType {
public var isNilOrEmpty: Bool {
guard let obj = self else { return true }
return obj.isEmpty
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment