Created
August 27, 2015 17:24
-
-
Save oisdk/311e7f314c39ac6725ec to your computer and use it in GitHub Desktop.
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 Occupiable { | |
var isEmpty: Bool { get } | |
var isNotEmpty: Bool { get } | |
} | |
public extension Occupiable { | |
public var isNotEmpty: Bool { return !isEmpty } | |
} | |
extension CollectionType where Self : Occupiable { } | |
extension String: Occupiable { } | |
public extension Optional where Wrapped : Occupiable { | |
var isNilOrEmpty: Bool { | |
return self?.isEmpty ?? false | |
} | |
var isNotNilOrEmpty: Bool { | |
return !isNilOrEmpty | |
} | |
} | |
let ar = [1, 2, 3, 4, 5] | |
ar.isNotEmpty | |
let optAr: [Int]? = [1, 2, 3, 4, 5] | |
optAr.isNilOrEmpty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment