FW

public class FW

全局包装器(因struct只读,只能用class)

自定义FW为任意名称(如APP)示例: public typealias APP = FW 使用示例: APP.safeString(object)

FW+Autoloader

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

    Declaration

    Swift

    @discardableResult
    public static func autoload(_ clazz: Any) -> Bool

FW+Benchmark

  • 标记时间调试开始

    Declaration

    Swift

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

    Parameters

    name

    调试标签,默认空字符串

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

    Declaration

    Swift

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

    Parameters

    name

    调试标签,默认空字符串

    Return Value

    消耗时间

FW+Logger

  • 记录跟踪日志

    Declaration

    Swift

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

    Parameters

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录调试日志

    Declaration

    Swift

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

    Parameters

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录信息日志

    Declaration

    Swift

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

    Parameters

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录警告日志

    Declaration

    Swift

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

    Parameters

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录错误日志

    Declaration

    Swift

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

    Parameters

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

  • 记录分组日志

    Declaration

    Swift

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

    Parameters

    group

    日志分组名称

    type

    日志类型

    format

    格式化字符串

    arguments

    可变参数列表,可不传

    file

    文件名,默认传参

    function

    方法名,默认传参

    line

    行数,默认传参

FW+Mediator

  • 中间件快速访问

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public static var router: Router.Type

FW+Promise

  • 仿协程异步执行方法

    Declaration

    Swift

    @discardableResult
    public static func async(_ block: @escaping () throws -> Any?) -> Promise
  • 仿协程同步返回结果

    Declaration

    Swift

    @discardableResult
    public static func await(_ promise: Promise) throws -> Any?

SafeValue

  • 安全字符串,不为nil

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public static func safeURL(_ value: Any?) -> URL

SafeType

  • 获取安全值

    Declaration

    Swift

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

    Declaration

    Swift

    public static func isEmpty<T>(_ value: T?) -> Bool where T : SafeType

FW+Language

  • 读取本地化字符串

    Declaration

    Swift

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

    Parameters

    key

    本地化键名

    table

    本地化表名,默认Localizable.strings

    Return Value

    本地化字符串

UIApplication

  • 是否是调试模式

    Declaration

    Swift

    public static let isDebug: Bool

UIDevice

  • 是否是模拟器

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public static var isMac: Bool { get }
  • 界面是否横屏

    Declaration

    Swift

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

    Declaration

    Swift

    public static var isDeviceLandscape: 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 }

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 isNotchedScreen: Bool { get }
  • 屏幕一像素的大小

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public static var toolBarHeight: 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) -> CGFloat
  • 获取相对设计图高度等比例缩放值

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public static func fixedHeight(_ value: CGFloat) -> CGFloat
  • 获取相对设计图等比例缩放size

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public static func relative(_ insets: UIEdgeInsets) -> UIEdgeInsets
  • 基于指定的倍数(0取当前设备),对传进来的floatValue进行像素取整

    Declaration

    Swift

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

FW+Block

  • 通用互斥锁方法

    Declaration

    Swift

    public static func synchronized(_ object: AnyObject, closure: () -> Void)
  • 通用互斥锁泛型方法

    Declaration

    Swift

    public func synchronized<T>(_ object: AnyObject, closure: () -> T) -> T

FW+Toolkit

  • 从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) -> UIFont

    Parameters

    size

    字体字号

    weight

    字重可选,默认Regular

    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对象