51 lines
1.1 KiB
Swift
51 lines
1.1 KiB
Swift
//
|
||
// NotEmpty.swift
|
||
// DLSDK
|
||
//
|
||
// Created by osell on 2023/11/17.
|
||
//
|
||
|
||
import Foundation
|
||
import Moya
|
||
|
||
public protocol NotEmptyProtocol {
|
||
/// 是否不为空
|
||
var isNotEmpty: Bool { get }
|
||
}
|
||
|
||
public extension NotEmptyProtocol {
|
||
var isNotEmpty: Bool { true }
|
||
}
|
||
|
||
/// 判断是否不为空
|
||
/// - Parameter objcet: T必须遵守NotEmptyProtocol
|
||
/// - Returns: 布尔值,true不为空,false为空
|
||
@discardableResult
|
||
public func NotEmpty<T: NotEmptyProtocol>(_ objcet: T?) -> Bool {
|
||
objcet?.isNotEmpty ?? false
|
||
}
|
||
|
||
|
||
extension String: NotEmptyProtocol {
|
||
public var isNotEmpty: Bool { trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false }
|
||
}
|
||
|
||
extension Array: NotEmptyProtocol {
|
||
public var isNotEmpty: Bool { count > 0 }
|
||
}
|
||
|
||
extension Dictionary: NotEmptyProtocol {
|
||
public var isNotEmpty: Bool { count > 0 }
|
||
}
|
||
|
||
extension Set: NotEmptyProtocol {
|
||
public var isNotEmpty: Bool { count > 0 }
|
||
}
|
||
|
||
extension NSObject: NotEmptyProtocol {}
|
||
extension Int: NotEmptyProtocol {}
|
||
extension Float: NotEmptyProtocol {}
|
||
extension Double: NotEmptyProtocol {}
|
||
extension CGFloat: NotEmptyProtocol {}
|
||
extension Response: NotEmptyProtocol {}
|