jsdw_ios/QuickLocation/Plugin/NotEmpty.swift

51 lines
1.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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 {}