Skip to content

Instantly share code, notes, and snippets.

@cozzin
Created August 8, 2018 14:40
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 cozzin/d6c45b51905d56f0bc8b097bb6aa4ce8 to your computer and use it in GitHub Desktop.
Save cozzin/d6c45b51905d56f0bc8b097bb6aa4ce8 to your computer and use it in GitHub Desktop.
check isNotEmpty isNotNilNotEmpty
//
// Emptiable+Extension.swift
// sieum
//
// Created by 홍성호 on 2018. 8. 8..
// Copyright © 2018년 홍성호. All rights reserved.
//
// https://github.com/artsy/Emergence/blob/master/Emergence/Extensions/Apple/Occupyable%2BisNotEmpty.swift
//
import Foundation
public protocol Emptiable {
var isEmpty: Bool { get }
var isNotEmpty: Bool { get }
}
extension Emptiable {
public var isNotEmpty: Bool {
return !isEmpty
}
}
extension String: Emptiable { }
extension Array: Emptiable { }
extension Dictionary: Emptiable { }
extension Set: Emptiable { }
extension Optional where Wrapped: Emptiable {
public var isNilOrEmtpy: Bool {
switch self {
case .none:
return true
case .some(let value):
return value.isEmpty
}
}
public var isNotNilNotEmpty: Bool {
return !isNilOrEmtpy
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment