jsdw_ios/QuickLocation/Core/Wrapper.swift

80 lines
2.0 KiB
Swift

//
// Wrapper.swift
// SHECommunity
//
// Created by 林 on 2024/11/25.
//
import Foundation
nonisolated public class DL {}
// nonisolated: 退出工程默认的 MainActor 隔离。
// 该通用包装类会在 Release(-O) 归档时触发 EarlyPerfInliner 对合成 deinit 的编译器崩溃。
nonisolated public class DLWrapper<Base> {
/// 原始对象
public private(set) var base: Base
/// 初始化方法
public init(_ base: Base) {
self.base = base
}
}
public protocol DLWrapperCompatible {
/// 关联类型
associatedtype WrapperBase
/// 类包装器属性
static var dl: DLWrapper<WrapperBase>.Type { get set }
/// 对象包装器属性
var dl: DLWrapper<WrapperBase> { get set }
}
extension DLWrapperCompatible {
/// 类包装器属性
public static var dl: DLWrapper<Self>.Type {
get { DLWrapper<Self>.self }
set {}
}
/// 对象包装器属性
public var dl: DLWrapper<Self> {
get { DLWrapper(self) }
set {}
}
}
// MARK: - DLWrapperCompatible
extension Int: DLWrapperCompatible {}
extension Int8: DLWrapperCompatible {}
extension Int16: DLWrapperCompatible {}
extension Int32: DLWrapperCompatible {}
extension Int64: DLWrapperCompatible {}
extension UInt: DLWrapperCompatible {}
extension UInt8: DLWrapperCompatible {}
extension UInt16: DLWrapperCompatible {}
extension UInt32: DLWrapperCompatible {}
extension UInt64: DLWrapperCompatible {}
extension Float: DLWrapperCompatible {}
extension Double: DLWrapperCompatible {}
extension Bool: DLWrapperCompatible {}
extension String: DLWrapperCompatible {}
extension Data: DLWrapperCompatible {}
extension Date: DLWrapperCompatible {}
extension URL: DLWrapperCompatible {}
extension URLRequest: DLWrapperCompatible {}
extension Array: DLWrapperCompatible {}
extension Set: DLWrapperCompatible {}
extension Dictionary: DLWrapperCompatible {}
extension CGFloat: DLWrapperCompatible {}
extension NSObject: DLWrapperCompatible {}