Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created August 27, 2015 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oisdk/311e7f314c39ac6725ec to your computer and use it in GitHub Desktop.
Save oisdk/311e7f314c39ac6725ec to your computer and use it in GitHub Desktop.
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