WrapperGlobal

public class WrapperGlobal

全局包装器

自定义WrapperGlobal为任意名称(如APP)示例:

public typealias APP = WrapperGlobal

使用示例:

APP.safeString(object)
  • 当前框架版本号

    Declaration

    Swift

    public static let version: String

WrapperGlobal

  • 自动加载Swift类并调用autoload方法,参数为Class或String

    Declaration

    Swift

    @discardableResult
    public static func autoload(_ clazz: Any) -> Bool
  • 标记时间调试开始

    Declaration

    Swift

    public static func begin(_ name: String = "")

    Parameters

    name

    调试标签,默认空字符串

  • 标记时间调试结束并打印消耗时间

    Declaration

    Swift

    @discardableResult
    public static func end(_ name: String = "") -> TimeInterval

    Parameters

    name

    调试标签,默认空字符串

    Return Value

    消耗时间

  • 记录详细日志

    Declaration

    Swift

    public static func verbose(
        group: String = "",
        _ format: String,
        _ arguments: CVarArg...,
        function: String = #function,
        file: String = #file,
        line: Int = #line
    )

    Parameters

    group

    日志分组,默认空

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录调试日志

    Declaration

    Swift

    public static func debug(
        group: String = "",
        _ format: String,
        _ arguments: CVarArg...,
        function: String = #function,
        file: String = #file,
        line: Int = #line
    )

    Parameters

    group

    日志分组,默认空

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录信息日志

    Declaration

    Swift

    public static func info(
        group: String = "",
        _ format: String,
        _ arguments: CVarArg...,
        function: String = #function,
        file: String = #file,
        line: Int = #line
    )

    Parameters

    group

    日志分组,默认空

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录警告日志

    Declaration

    Swift

    public static func warn(
        group: String = "",
        _ format: String,
        _ arguments: CVarArg...,
        function: String = #function,
        file: String = #file,
        line: Int = #line
    )

    Parameters

    group

    日志分组,默认空

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录错误日志

    Declaration

    Swift

    public static func error(
        group: String = "",
        _ format: String,
        _ arguments: CVarArg...,
        function: String = #function,
        file: String = #file,
        line: Int = #line
    )

    Parameters

    group

    日志分组,默认空

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录类型日志

    Declaration

    Swift

    public static func log(
        type: LogType,
        group: String = "",
        _ format: String,
        _ arguments: CVarArg...,
        function: String = #function,
        file: String = #file,
        line: Int = #line
    )

    Parameters

    type

    日志类型

    group

    日志分组,默认空

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 中间件快速访问

    Declaration

    Swift

    public static let mediator: Mediator.Type
  • 插件快速访问

    Declaration

    Swift

    public static let plugin: PluginManager.Type
  • 路由快速访问

    Declaration

    Swift

    public static let router: Router.Type
  • 安全字符串,不为nil

    Declaration

    Swift

    public static func safeString(_ value: Any?) -> String
  • 安全数字,不为nil

    Declaration

    Swift

    public static func safeNumber(_ value: Any?) -> NSNumber
  • 安全Int,不为nil

    Declaration

    Swift

    public static func safeInt(_ value: Any?) -> Int
  • 安全Bool,不为nil

    Declaration

    Swift

    public static func safeBool(_ value: Any?) -> Bool
  • 安全Float,不为nil

    Declaration

    Swift

    public static func safeFloat(_ value: Any?) -> Float
  • 安全Double,不为nil

    Declaration

    Swift

    public static func safeDouble(_ value: Any?) -> Double
  • 安全URL,不为nil,不兼容文件路径(需fileURLWithPath)

    Declaration

    Swift

    public static func safeURL(_ value: Any?) -> URL
  • 获取安全值

    Declaration

    Swift

    public static func safeValue<T>(_ value: T?) -> T where T : BasicType
  • 判断是否不为空

    Declaration

    Swift

    public static func isNotEmpty<T>(_ value: T?) -> Bool where T : BasicType
  • 判断是否为nil,兼容嵌套Optional

    Declaration

    Swift

    public static func isNil(_ value: Any?) -> Bool
  • 根据名称加载UIImage,优先加载图片文件(无缓存),文件不存在时尝试系统imageNamed方式(有缓存)

    Declaration

    Swift

    public static func image(_ named: String, bundle: Bundle? = nil) -> UIImage?

UIApplication

  • 是否是调试模式

    Declaration

    Swift

    public static var isDebug: Bool { get }

UIDevice

  • 是否是模拟器

    Declaration

    Swift

    public static var isSimulator: Bool { get }
  • 是否是iPhone设备

    Declaration

    Swift

    public static var isIphone: Bool { get }
  • 是否是iPod设备

    Declaration

    Swift

    public static var isIpod: Bool { get }
  • 是否是iPad设备

    Declaration

    Swift

    public static var isIpad: Bool { get }
  • 是否是Mac设备

    Declaration

    Swift

    public static var isMac: Bool { get }
  • iOS系统版本

    Declaration

    Swift

    public static var iosVersion: Double { get }
  • 是否是指定iOS主版本

    Declaration

    Swift

    public static func isIos(_ version: Int) -> Bool
  • 是否是大于等于指定iOS主版本

    Declaration

    Swift

    public static func isIosLater(_ version: Int) -> Bool
  • 设备尺寸,跟横竖屏无关

    Declaration

    Swift

    public static var deviceSize: CGSize { get }
  • 设备宽度,跟横竖屏无关

    Declaration

    Swift

    public static var deviceWidth: CGFloat { get }
  • 设备高度,跟横竖屏无关

    Declaration

    Swift

    public static var deviceHeight: CGFloat { get }
  • 设备分辨率,跟横竖屏无关

    Declaration

    Swift

    public static var deviceResolution: CGSize { get }
  • 设备是否横屏,无论支不支持横屏

    Declaration

    Swift

    public static var isDeviceLandscape: Bool { get }

UIScreen

  • 屏幕尺寸

    Declaration

    Swift

    public static var screenSize: CGSize { get }
  • 屏幕宽度

    Declaration

    Swift

    public static var screenWidth: CGFloat { get }
  • 屏幕高度

    Declaration

    Swift

    public static var screenHeight: CGFloat { get }
  • 屏幕像素比例

    Declaration

    Swift

    public static var screenScale: CGFloat { get }
  • 判断屏幕英寸,需同步适配新机型

    Declaration

    Swift

    public static func isScreenInch(_ inch: ScreenInch) -> Bool
  • 界面是否横屏

    Declaration

    Swift

    public static var isInterfaceLandscape: Bool { get }
  • 是否是全面屏屏幕

    Declaration

    Swift

    @MainActor
    public static var isNotchedScreen: Bool { get }
  • 是否是灵动岛屏幕

    Declaration

    Swift

    @MainActor
    public static var isDynamicIsland: Bool { get }
  • 屏幕一像素的大小

    Declaration

    Swift

    public static var pixelOne: CGFloat { get }
  • 屏幕半个点的大小,区别于pixelOne,2x屏为1像素,3x屏为2像素

    Declaration

    Swift

    public static var pointHalf: CGFloat { get }
  • 屏幕安全区域距离

    Declaration

    Swift

    @MainActor
    public static var safeAreaInsets: UIEdgeInsets { get }
  • 状态栏高度,与是否隐藏无关

    Declaration

    Swift

    @MainActor
    public static var statusBarHeight: CGFloat { get }
  • 导航栏高度,与是否隐藏无关

    Declaration

    Swift

    @MainActor
    public static var navigationBarHeight: CGFloat { get }
  • 顶部栏高度,包含状态栏、导航栏,与是否隐藏无关

    Declaration

    Swift

    @MainActor
    public static var topBarHeight: CGFloat { get }
  • 标签栏高度,与是否隐藏无关

    Declaration

    Swift

    @MainActor
    public static var tabBarHeight: CGFloat { get }
  • 工具栏高度,与是否隐藏无关

    Declaration

    Swift

    @MainActor
    public static var toolBarHeight: CGFloat { get }
  • 当前等比例缩放参考设计图宽度,默认375

    Declaration

    Swift

    public static var referenceWidth: CGFloat { get }
  • 当前等比例缩放参考设计图高度,默认812

    Declaration

    Swift

    public static var referenceHeight: CGFloat { get }
  • 当前屏幕宽度缩放比例

    Declaration

    Swift

    public static var relativeScale: CGFloat { get }
  • 当前屏幕高度缩放比例

    Declaration

    Swift

    public static var relativeHeightScale: CGFloat { get }
  • 获取相对设计图宽度等比例缩放值

    Declaration

    Swift

    public static func relative(_ value: CGFloat, flat: Bool = false) -> CGFloat
  • 获取相对设计图等比例缩放size

    Declaration

    Swift

    public static func relative(_ size: CGSize, flat: Bool = false) -> CGSize
  • 获取相对设计图等比例缩放point

    Declaration

    Swift

    public static func relative(_ point: CGPoint, flat: Bool = false) -> CGPoint
  • 获取相对设计图等比例缩放rect

    Declaration

    Swift

    public static func relative(_ rect: CGRect, flat: Bool = false) -> CGRect
  • 获取相对设计图等比例缩放insets

    Declaration

    Swift

    public static func relative(_ insets: UIEdgeInsets, flat: Bool = false) -> UIEdgeInsets
  • 获取相对设计图宽度等比例缩放时的固定宽度值

    Declaration

    Swift

    public static func fixed(_ value: CGFloat, flat: Bool = false) -> CGFloat
  • 获取相对设计图等比例缩放时的固定size

    Declaration

    Swift

    public static func fixed(_ size: CGSize, flat: Bool = false) -> CGSize
  • 获取相对设计图等比例缩放时的固定point

    Declaration

    Swift

    public static func fixed(_ point: CGPoint, flat: Bool = false) -> CGPoint
  • 获取相对设计图等比例缩放时的固定rect

    Declaration

    Swift

    public static func fixed(_ rect: CGRect, flat: Bool = false) -> CGRect
  • 获取相对设计图等比例缩放时的固定insets

    Declaration

    Swift

    public static func fixed(_ insets: UIEdgeInsets, flat: Bool = false) -> UIEdgeInsets
  • 获取相对设计图高度等比例缩放值

    Declaration

    Swift

    public static func relativeHeight(_ value: CGFloat, flat: Bool = false) -> CGFloat
  • 获取相对设计图高度等比例缩放时的固定高度值

    Declaration

    Swift

    public static func fixedHeight(_ value: CGFloat, flat: Bool = false) -> CGFloat
  • 基于指定的倍数(0取当前设备),对传进来的floatValue进行像素取整

    Declaration

    Swift

    public static func flat(_ value: CGFloat, scale: CGFloat = 0) -> CGFloat
  • 基于指定的倍数(0取当前设备),对传进来的size进行像素取整

    Declaration

    Swift

    public static func flat(_ size: CGSize, scale: CGFloat = 0) -> CGSize
  • 基于指定的倍数(0取当前设备),对传进来的point进行像素取整

    Declaration

    Swift

    public static func flat(_ point: CGPoint, scale: CGFloat = 0) -> CGPoint
  • 基于指定的倍数(0取当前设备),对传进来的rect进行像素取整

    Declaration

    Swift

    public static func flat(_ rect: CGRect, scale: CGFloat = 0) -> CGRect
  • 基于指定的倍数(0取当前设备),对传进来的insets进行像素取整

    Declaration

    Swift

    public static func flat(_ insets: UIEdgeInsets, scale: CGFloat = 0) -> UIEdgeInsets

WrapperGlobal

  • 注册自定义Codable解码转换器

    Declaration

    Swift

    public static func register(_ decodingConverter: CodableDecodingConverter)

    Parameters

    decodingConverter

    解码转换器

  • 通用互斥锁方法

    Declaration

    Swift

    public static func synchronized(_ object: Any, closure: () -> Void)
  • 通用互斥锁方法,返回指定对象

    Declaration

    Swift

    public static func synchronized<T>(_ object: Any, closure: () -> T) -> T
  • 同一个token仅执行一次block,全局范围

    Declaration

    Swift

    public static func dispatchOnce(
        _ token: AnyHashable,
        closure: () -> Void
    )
  • 读取本地化字符串

    Declaration

    Swift

    public static func localized(_ key: String, _ table: String? = nil) -> String

    Parameters

    key

    本地化键名

    table

    本地化表名,默认Localizable.strings

    Return Value

    本地化字符串

  • 从16进制创建UIColor

    Declaration

    Swift

    public static func color(_ hex: Int, _ alpha: CGFloat = 1.0) -> UIColor

    Parameters

    hex

    十六进制值,格式0xFFFFFF

    alpha

    透明度可选,默认1.0

    Return Value

    UIColor

  • 从RGB创建UIColor

    Declaration

    Swift

    public static func color(_ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, _ alpha: CGFloat = 1.0) -> UIColor

    Parameters

    red

    红色值

    green

    绿色值

    blue

    蓝色值

    alpha

    透明度可选,默认1.0

    Return Value

    UIColor

  • 快速创建系统字体,自动等比例缩放

    Declaration

    Swift

    public static func font(_ size: CGFloat, _ weight: UIFont.Weight = .regular, autoScale: Bool? = nil) -> UIFont

    Parameters

    size

    字体字号

    weight

    字重可选,默认Regular

    autoScale

    是否自动等比例缩放,默认全局配置

    Return Value

    UIFont

  • 快速创建图标对象

    Declaration

    Swift

    public static func icon(_ named: String, _ size: CGFloat) -> Icon?

    Parameters

    named

    图标名称

    size

    图标大小

    Return Value

    FWIcon对象

  • 快速创建图标图像

    Declaration

    Swift

    public static func iconImage(_ name: String, _ size: CGFloat) -> UIImage?

    Parameters

    name

    图标名称

    size

    图片大小

    Return Value

    UIImage对象