Created
August 5, 2015 02:12
-
-
Save azone/6e120333e725aa639dde to your computer and use it in GitHub Desktop.
determine the CollectionType or String is nil or empty
This file contains 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
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