Wrapper

public class Wrapper<Base>

属性包装器

  • 原始对象

    Declaration

    Swift

    public let base: Base
  • 初始化方法

    Declaration

    Swift

    public init(_ base: Base)

Wrapper

  • Undocumented

    Declaration

    Swift

    public var safeInt: Int { get }
  • Undocumented

    Declaration

    Swift

    public var safeBool: Bool { get }
  • Undocumented

    Declaration

    Swift

    public var safeFloat: Float { get }
  • Undocumented

    Declaration

    Swift

    public var safeDouble: Double { get }
  • Undocumented

    Declaration

    Swift

    public var safeString: String { get }
  • Undocumented

    Declaration

    Swift

    public var safeNumber: NSNumber { get }
  • Undocumented

    Declaration

    Swift

    public var safeArray: [Any] { get }
  • Undocumented

    Declaration

    Swift

    public var safeDictionary: [AnyHashable : Any] { get }
  • Undocumented

    Declaration

    Swift

    public var safeJSON: JSON { get }

Observer

  • 监听某个点对点消息,可指定对象,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeMessage(_ name: Notification.Name, object: AnyObject? = nil, block: @escaping (Notification) -> Void) -> NSObjectProtocol

    Parameters

    name

    消息名称

    object

    消息对象,值为nil时表示所有

    block

    消息句柄

    Return Value

    监听者

  • 监听某个指定对象点对点消息,可指定对象,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeMessage(_ name: Notification.Name, object: AnyObject? = nil, target: AnyObject?, action: Selector) -> NSObjectProtocol

    Parameters

    name

    消息名称

    object

    消息对象,值为nil时表示所有

    target

    消息目标

    action

    目标动作,参数为通知对象

    Return Value

    监听者

  • 手工移除某个点对点消息指定监听,可指定对象

    Declaration

    Swift

    public func unobserveMessage(_ name: Notification.Name, object: AnyObject? = nil, target: AnyObject? = nil, action: Selector? = nil)

    Parameters

    name

    消息名称

    object

    消息对象,值为nil时表示所有

    target

    消息目标

    action

    目标动作

  • 手工移除某个指定对象点对点消息指定监听

    Declaration

    Swift

    @discardableResult
    public func unobserveMessage(observer: Any) -> Bool

    Parameters

    observer

    监听者

  • 手工移除所有点对点消息监听

    Declaration

    Swift

    public func unobserveAllMessages()

Subject

  • 发送点对点消息,附带对象和用户信息

    Declaration

    Swift

    public func sendMessage(_ name: Notification.Name, object: AnyObject? = nil, userInfo: [AnyHashable : Any]? = nil, to receiver: some WrapperObject)

    Parameters

    name

    消息名称

    object

    消息对象,默认nil

    userInfo

    用户信息,默认nil

    receiver

    消息接收者

  • 发送点对点消息,附带对象和用户信息

    Declaration

    Swift

    public static func sendMessage(_ name: Notification.Name, object: AnyObject? = nil, userInfo: [AnyHashable : Any]? = nil, to receiver: some WrapperObject)

    Parameters

    name

    消息名称

    object

    消息对象,默认nil

    userInfo

    用户信息,默认nil

    receiver

    消息接收者

Observer

  • 监听某个广播通知,可指定对象,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeNotification(_ name: Notification.Name, object: AnyObject? = nil, block: @escaping (Notification) -> Void) -> NSObjectProtocol

    Parameters

    name

    通知名称

    object

    通知对象,值为nil时表示所有

    block

    通知句柄

    Return Value

    监听者

  • 监听某个广播通知,可指定对象,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeNotification(_ name: Notification.Name, object: AnyObject? = nil, target: AnyObject?, action: Selector) -> NSObjectProtocol

    Parameters

    name

    通知名称

    object

    通知对象,值为nil时表示所有

    target

    通知目标

    action

    目标动作,参数为通知对象

    Return Value

    监听者

  • 单次监听通知,触发后自动移除监听

    Declaration

    Swift

    public static func observeOnce(
        forName name: NSNotification.Name?,
        object: Any? = nil,
        queue: OperationQueue? = nil,
        using block: @escaping (_ notification: Notification) -> Void
    )

    Parameters

    name

    通知名称

    object

    通知对象,值为nil时表示所有

    queue

    通知队列

    block

    监听句柄

  • 手工移除某个广播通知指定监听,可指定对象

    Declaration

    Swift

    public func unobserveNotification(_ name: Notification.Name, object: AnyObject? = nil, target: AnyObject? = nil, action: Selector? = nil)

    Parameters

    name

    通知名称

    object

    通知对象,值为nil时表示所有

    target

    通知目标

    action

    目标动作

  • 手工移除某个指定对象广播通知指定监听

    Declaration

    Swift

    @discardableResult
    public func unobserveNotification(observer: Any) -> Bool

    Parameters

    observer

    监听者

  • 手工移除所有点对点消息监听

    Declaration

    Swift

    public func unobserveAllNotifications()

Subject

  • 发送广播通知,附带对象和用户信息

    Declaration

    Swift

    public func postNotification(_ name: Notification.Name, object: Any? = nil, userInfo: [AnyHashable : Any]? = nil)

    Parameters

    name

    通知名称

    object

    通知对象

    userInfo

    用户信息

  • 发送广播通知,附带对象和用户信息

    Declaration

    Swift

    public static func postNotification(_ name: Notification.Name, object: Any? = nil, userInfo: [AnyHashable : Any]? = nil)

    Parameters

    name

    通知名称

    object

    通知对象

    userInfo

    用户信息

Available where Base: NSObject

  • 监听对象某个属性KeyPath,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeProperty<Value>(_ keyPath: KeyPath<Base, Value>, options: NSKeyValueObservingOptions = [], block: @escaping (Base, NSKeyValueObservedChange<Value>) -> Void) -> NSObjectProtocol

    Parameters

    keyPath

    属性KeyPath

    options

    监听选项

    block

    目标句柄,block参数依次为object、change对象

    Return Value

    监听者

  • 监听对象某个属性KeyPath,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeProperty<Value>(_ keyPath: KeyPath<Base, Value>, options: NSKeyValueObservingOptions = [], target: AnyObject?, action: Selector) -> NSObjectProtocol

    Parameters

    keyPath

    属性KeyPath

    options

    监听选项

    target

    目标对象

    action

    目标动作,action参数依次为object、change对象

    Return Value

    监听者

  • 监听对象某个属性,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeProperty(_ property: String, block: @escaping (Base, [NSKeyValueChangeKey : Any]) -> Void) -> NSObjectProtocol

    Parameters

    property

    属性名称

    block

    目标句柄,block参数依次为object、优化的change字典(不含NSNull)

    Return Value

    监听者

  • 监听对象某个属性,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func observeProperty(_ property: String, target: AnyObject?, action: Selector) -> NSObjectProtocol

    Parameters

    property

    属性名称

    target

    目标对象

    action

    目标动作,action参数依次为object、优化的change字典(不含NSNull)

    Return Value

    监听者

  • 手工移除某个属性指定KeyPath监听

    Declaration

    Swift

    public func unobserveProperty<Value>(_ keyPath: KeyPath<Base, Value>, target: AnyObject? = nil, action: Selector? = nil)

    Parameters

    keyPath

    属性KeyPath

    target

    目标对象,值为nil时移除所有对象(同UIControl)

    action

    目标动作,值为nil时移除所有动作(同UIControl)

  • 手工移除某个属性指定监听

    Declaration

    Swift

    public func unobserveProperty(_ property: String, target: AnyObject? = nil, action: Selector? = nil)

    Parameters

    property

    属性名称

    target

    目标对象,值为nil时移除所有对象(同UIControl)

    action

    目标动作,值为nil时移除所有动作(同UIControl)

  • 手工移除某个属性指定监听

    Declaration

    Swift

    @discardableResult
    public func unobserveProperty(observer: Any) -> Bool

    Parameters

    observer

    监听者

  • 手工移除所有属性所有监听

    Declaration

    Swift

    public func unobserveAllProperties()
  • 手工添加指定KeyPath监听,对象释放时自动移除监听,添加多次执行多次

    Declaration

    Swift

    @discardableResult
    public func addObservation(_ observation: NSKeyValueObservation, keyPath: AnyHashable? = nil, target: AnyObject? = nil, action: Selector? = nil) -> NSObjectProtocol

    Parameters

    observation

    监听对象

    keyPath

    属性keyPath

    target

    目标对象

    action

    目标动作

    Return Value

    监听者

  • 手工移除指定KeyPath监听

    Declaration

    Swift

    @discardableResult
    public func removeObservation(_ observation: NSKeyValueObservation) -> Bool

    Parameters

    observation

    监听对象

    Return Value

    是否移除成功

Static

  • 获取当前主window,可自定义

    Declaration

    Swift

    public static var main: UIWindow? { get set }
  • 获取当前主场景,可自定义

    Declaration

    Swift

    public static var mainScene: UIWindowScene? { get set }

Public

  • 获取最顶部的视图控制器

    Declaration

    Swift

    public var topViewController: UIViewController? { get }
  • 获取最顶部的导航栏控制器。如果顶部VC不含导航栏,返回nil

    Declaration

    Swift

    public var topNavigationController: UINavigationController? { get }
  • 获取最顶部的显示控制器

    Declaration

    Swift

    public var topPresentedController: UIViewController? { get }
  • 使用最顶部的导航栏控制器打开控制器

    Declaration

    Swift

    @discardableResult
    public func push(_ viewController: UIViewController, animated: Bool = true) -> Bool
  • 使用最顶部的导航栏控制器打开控制器,同时pop指定数量控制器

    Declaration

    Swift

    @discardableResult
    public func push(_ viewController: UIViewController, pop count: Int, animated: Bool = true) -> Bool
  • 使用最顶部的显示控制器弹出控制器,建议present导航栏控制器(可用来push)

    Declaration

    Swift

    public func present(_ viewController: UIViewController, animated: Bool = true, completion: (() -> Void)? = nil)
  • 使用最顶部的视图控制器打开控制器,自动判断push|present

    Declaration

    Swift

    public func open(_ viewController: UIViewController, animated: Bool = true, options: NavigatorOptions = [], completion: (() -> Void)? = nil)
  • 关闭最顶部的视图控制器,自动判断pop|dismiss,返回是否成功

    Declaration

    Swift

    @discardableResult
    public func close(animated: Bool = true, options: NavigatorOptions = [], completion: (() -> Void)? = nil) -> Bool

Navigation

  • 打开控制器。1.如果打开导航栏,则调用present;2.否则如果导航栏存在,则调用push;3.否则调用present

    Declaration

    Swift

    public func open(_ viewController: UIViewController, animated: Bool = true, options: NavigatorOptions = [], completion: (() -> Void)? = nil)
  • 关闭控制器,返回是否成功。1.如果导航栏不存在,则调用dismiss;2.否则如果已是导航栏底部,则调用dismiss;3.否则调用pop

    Declaration

    Swift

    @discardableResult
    public func close(animated: Bool = true, options: NavigatorOptions = [], completion: (() -> Void)? = nil) -> Bool

Workflow

  • 自定义工作流名称,支持二级(“."分隔);默认返回小写类名(去掉ViewController、Controller)

    Declaration

    Swift

    public var workflowName: String { get set }

Navigation

  • push新界面,完成时回调

    Declaration

    Swift

    public func pushViewController(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)? = nil)
  • pop当前界面,完成时回调

    Declaration

    Swift

    @discardableResult
    public func popViewController(animated: Bool, completion: (() -> Void)? = nil) -> UIViewController?
  • pop到指定界面,完成时回调

    Declaration

    Swift

    @discardableResult
    public func popToViewController(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)? = nil) -> [UIViewController]?
  • pop到根界面,完成时回调

    Declaration

    Swift

    @discardableResult
    public func popToRootViewController(animated: Bool, completion: (() -> Void)? = nil) -> [UIViewController]?
  • 设置界面数组,完成时回调

    Declaration

    Swift

    public func setViewControllers(_ viewControllers: [UIViewController], animated: Bool, completion: (() -> Void)? = nil)
  • push新界面,同时pop指定数量界面,至少保留一个根控制器,完成时回调

    Declaration

    Swift

    public func pushViewController(_ viewController: UIViewController, pop count: Int, animated: Bool, completion: (() -> Void)? = nil)
  • pop指定数量界面,0不会pop,至少保留一个根控制器,完成时回调

    Declaration

    Swift

    @discardableResult
    public func popViewControllers(_ count: Int, animated: Bool, completion: (() -> Void)? = nil) -> [UIViewController]?

Workflow

  • 当前最外层工作流名称,即topViewController的工作流名称

    Declaration

    Swift

    public var topWorkflowName: String? { get }
  • push控制器,并清理最外层工作流(不属于工作流则不清理)

    示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4、(5、6)、9

    Declaration

    Swift

    public func push(_ viewController: UIViewController, popTopWorkflowAnimated animated: Bool, completion: (() -> Void)? = nil)
  • push控制器,并清理到指定工作流(不属于工作流则清理)

    示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、9

    Declaration

    Swift

    public func push(_ viewController: UIViewController, popToWorkflow: String, animated: Bool, completion: (() -> Void)? = nil)
  • push控制器,并清理非根控制器(只保留根控制器)

    示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、9

    Declaration

    Swift

    public func push(_ viewController: UIViewController, popToRootWorkflowAnimated animated: Bool, completion: (() -> Void)? = nil)
  • push控制器,并从外到内清理指定工作流,直到遇到不属于指定工作流的控制器停止

    示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4、9

    Declaration

    Swift

    public func push(_ viewController: UIViewController, popWorkflows workflows: [String]?, animated: Bool = true, completion: (() -> Void)? = nil)
  • pop方式清理最外层工作流,至少保留一个根控制器(不属于工作流则不清理)

    示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4、(5、6)

    Declaration

    Swift

    public func popTopWorkflow(animated: Bool = true, completion: (() -> Void)? = nil)
  • pop方式清理到指定工作流,至少保留一个根控制器(不属于工作流则清理)

    示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)

    Declaration

    Swift

    public func popToWorkflow(_ workflow: String, animated: Bool = true, completion: (() -> Void)? = nil)
  • pop方式从外到内清理指定工作流,直到遇到不属于指定工作流的控制器停止,至少保留一个根控制器

    示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4

    Declaration

    Swift

    public func popWorkflows(_ workflows: [String]?, animated: Bool = true, completion: (() -> Void)? = nil)

Module

  • 获取当前类所在的模块名称,兼容主应用和framework等(可能不准确)

    Declaration

    Swift

    public static var moduleName: String { get }
  • 获取指定类所在的模块名称,兼容主应用和framework等(可能不准确)

    Declaration

    Swift

    public static func moduleName(for aClass: AnyClass) -> String
  • 获取任意对象的类型字符串,含模块名称

    Declaration

    Swift

    public static func typeName(for object: Any) -> String

Runtime

  • 安全调用方法,支持多个参数

    Declaration

    Swift

    @discardableResult
    public func invokeMethod(_ selector: Selector, objects: [Any]? = nil) -> Unmanaged<AnyObject>!

    Parameters

    selector

    要执行的方法

    objects

    传递的参数数组,默认空

    Return Value

    方法返回值

  • 安全调用内部属性获取方法,如果属性不存在,则忽略之

    如果iOS13系统UIView调用部分valueForKey:方法闪退,且没有好的替代方案,可尝试调用此方法

    Declaration

    Swift

    public func invokeGetter(_ name: String) -> Any?

    Parameters

    name

    内部属性名称

    Return Value

    属性值

  • 安全调用内部属性设置方法,如果属性不存在,则忽略之

    如果iOS13系统UIView调用部分valueForKey:方法闪退,且没有好的替代方案,可尝试调用此方法

    Declaration

    Swift

    public func invokeSetter(_ name: String, object: Any?)

    Parameters

    name

    内部属性名称

    object

    传递的方法参数

  • 安全调用类方法,支持多个参数

    Declaration

    Swift

    @discardableResult
    public static func invokeMethod(_ target: AnyObject, selector: Selector, objects: [Any]? = nil) -> Unmanaged<AnyObject>!

    Parameters

    target

    调用的目标

    selector

    要执行的方法

    objects

    传递的参数数组,默认空

    Return Value

    方法返回值

Property

  • 临时对象,强引用,支持KVO

    Declaration

    Swift

    public var tempObject: Any? { get set }
  • 读取关联属性

    Declaration

    Swift

    public func property(forName name: String) -> Any?

    Parameters

    name

    属性名称

    Return Value

    属性值

  • 读取Bool关联属性,默认false

    Declaration

    Swift

    public func propertyBool(forName name: String) -> Bool

    Parameters

    name

    属性名称

    Return Value

    属性值

  • 读取Int关联属性,默认0

    Declaration

    Swift

    public func propertyInt(forName name: String) -> Int

    Parameters

    name

    属性名称

    Return Value

    属性值

  • 读取Double关联属性,默认0

    Declaration

    Swift

    public func propertyDouble(forName name: String) -> Double

    Parameters

    name

    属性名称

    Return Value

    属性值

  • 读取NSNumber关联属性,默认nil

    Declaration

    Swift

    public func propertyNumber(forName name: String) -> NSNumber?

    Parameters

    name

    属性名称

    Return Value

    属性值

  • 设置关联属性,可指定关联策略,支持KVO

    Declaration

    Swift

    public func setProperty(_ value: Any?, forName name: String, policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC)

    Parameters

    value

    属性值

    name

    属性名称

    policy

    关联策略,默认RETAIN_NONATOMIC

  • 设置拷贝关联属性,支持KVO

    Declaration

    Swift

    public func setPropertyCopy(_ value: Any?, forName name: String)

    Parameters

    value

    属性值

    name

    属性名称

  • 设置弱引用关联属性,支持KVO,OC不支持weak关联属性

    Declaration

    Swift

    public func setPropertyWeak(_ value: AnyObject?, forName name: String)

    Parameters

    value

    属性值

    name

    属性名称

  • 设置Bool关联属性

    Declaration

    Swift

    public func setPropertyBool(_ value: Bool, forName name: String)

    Parameters

    value

    属性值

    name

    属性名称

  • 设置Int关联属性

    Declaration

    Swift

    public func setPropertyInt(_ value: Int, forName name: String)

    Parameters

    value

    属性值

    name

    属性名称

  • 设置Double关联属性

    Declaration

    Swift

    public func setPropertyDouble(_ value: Double, forName name: String)

    Parameters

    value

    属性值

    name

    属性名称

  • 设置NSNumber关联属性

    Declaration

    Swift

    public func setPropertyNumber(_ value: NSNumber?, forName name: String)

    Parameters

    value

    属性值

    name

    属性名称

Bind

  • 给对象绑定上另一个对象以供后续取出使用,如果 object 传入 nil 则会清除该 key 之前绑定的对象

    Declaration

    Swift

    public func bindObject(_ object: Any?, forKey key: String)

    Parameters

    object

    对象,会被 strong 强引用

    forKey

    键名

  • 给对象绑定上另一个弱引用对象以供后续取出使用,如果 object 传入 nil 则会清除该 key 之前绑定的对象

    Declaration

    Swift

    public func bindObjectWeak(_ object: AnyObject?, forKey key: String)

    Parameters

    object

    对象,不会被 strong 强引用

    forKey

    键名

  • 取出之前使用 bind 方法绑定的对象

    Declaration

    Swift

    public func boundObject(forKey key: String) -> Any?

    Parameters

    forKey

    键名

    Return Value

    绑定的对象

  • 给对象绑定上一个 double 值以供后续取出使用

    Declaration

    Swift

    public func bindDouble(_ value: Double, forKey: String)

    Parameters

    value

    double值

    forKey

    键名

  • 取出之前用 bindDouble:forKey: 绑定的值

    Declaration

    Swift

    public func boundDouble(forKey: String) -> Double

    Parameters

    forKey

    键名

    Return Value

    绑定的值

  • 给对象绑定上一个 BOOL 值以供后续取出使用

    Declaration

    Swift

    public func bindBool(_ value: Bool, forKey: String)

    Parameters

    value

    布尔值

    forKey

    键名

  • 取出之前用 bindBool:forKey: 绑定的值

    Declaration

    Swift

    public func boundBool(forKey: String) -> Bool

    Parameters

    forKey

    键名

    Return Value

    绑定的值

  • 给对象绑定上一个 NSInteger 值以供后续取出使用

    Declaration

    Swift

    public func bindInt(_ value: Int, forKey: String)

    Parameters

    value

    整数值

    forKey

    键名

  • 取出之前用 bindInt:forKey: 绑定的值

    Declaration

    Swift

    public func boundInt(forKey: String) -> Int

    Parameters

    forKey

    键名

    Return Value

    绑定的值

  • 给对象绑定上一个 NSNumber 值以供后续取出使用

    Declaration

    Swift

    public func bindNumber(_ value: NSNumber?, forKey: String)

    Parameters

    value

    整数值

    forKey

    键名

  • 取出之前用 bindNumber:forKey: 绑定的值

    Declaration

    Swift

    public func boundNumber(forKey: String) -> NSNumber?

    Parameters

    forKey

    键名

    Return Value

    绑定的值

  • 移除之前使用 bind 方法绑定的对象

    Declaration

    Swift

    public func removeBinding(forKey key: String)

    Parameters

    forKey

    键名

  • 移除之前使用 bind 方法绑定的所有对象

    Declaration

    Swift

    public func removeAllBindings()
  • 返回当前有绑定对象存在的所有的 key 的数组,数组中元素的顺序是随机的,如果不存在任何 key,则返回一个空数组

    Declaration

    Swift

    public func allBindingKeys() -> [String]
  • 返回是否设置了某个 key

    Declaration

    Swift

    public func hasBindingKey(_ key: String) -> Bool

    Parameters

    key

    键名

    Return Value

    是否绑定

Hash

  • 获取当前对象的hashValue,等同于: ObjectIdentifier(base).hashValue

    Declaration

    Swift

    public var hashValue: Int { get }

Mirror

  • 获取当前对象的反射字典(含父类直至NSObject),不含nil值

    Declaration

    Swift

    public var mirrorDictionary: [String : Any] { get }

Class

  • 获取指定类的metaClass

    Declaration

    Swift

    public static func metaClass(_ clazz: Any?) -> AnyClass?

    Parameters

    clazz

    支持AnyClass|NSObject对象

    Return Value

    参数为AnyClass时,返回metaClass;参数为NSObject对象时,返回NSObject类

  • 获取指定类的所有子类

    Declaration

    Swift

    public static func allSubclasses(_ clazz: AnyClass) -> [AnyClass]
  • 获取类方法列表(含父类直至NSObject),支持meta类(objc_getMetaClass)

    Declaration

    Swift

    public static func classMethods(_ clazz: AnyClass) -> [String]

    Parameters

    clazz

    指定类

    Return Value

    方法列表

  • 获取类属性列表(含父类直至NSObject),支持meta类(objc_getMetaClass)

    Declaration

    Swift

    public static func classProperties(_ clazz: AnyClass) -> [String]

    Parameters

    clazz

    指定类

    Return Value

    属性列表

  • 获取类Ivar列表(含父类直至NSObject),支持meta类(objc_getMetaClass)

    Declaration

    Swift

    public static func classIvars(_ clazz: AnyClass) -> [String]

    Parameters

    clazz

    指定类

    Return Value

    Ivar列表

Property

  • 读取关联对象,key为字符串,一般可使用#function

    Declaration

    Swift

    public static func getAssociatedObject(_ object: Any, key: String) -> Any?
  • 设置关联对象,key为字符串,一般可使用#function

    Declaration

    Swift

    public static func setAssociatedObject(_ object: Any, key: String, value: Any?, policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC)

Mirror

  • 执行任意对象的反射属性句柄(含父类)

    Declaration

    Swift

    public static func mirrorMap(_ object: Any, block: (String, Any) throws -> Void) rethrows
  • 获取任意对象的反射字典(含父类直至NSObject),不含nil值

    Declaration

    Swift

    public static func mirrorDictionary(_ object: Any?) -> [String : Any]

Available where Base == Data

  • 转换为UTF8字符串

    Declaration

    Swift

    public var utf8String: String? { get }

Available where Base == String

  • 安全字符串,不为nil

    Declaration

    Swift

    public static func safeString(_ value: Any?) -> String
  • 去掉首尾空白字符

    Declaration

    Swift

    public var trimString: String { get }
  • 首字母大写

    Declaration

    Swift

    public var ucfirstString: String { get }
  • 首字母小写

    Declaration

    Swift

    public var lcfirstString: String { get }
  • 驼峰转下划线

    Declaration

    Swift

    public var underlineString: String { get }
  • 下划线转驼峰

    Declaration

    Swift

    public var camelString: String { get }
  • 转换为UTF8数据

    Declaration

    Swift

    public var utf8Data: Data? { get }
  • url

    转换为URL

    Declaration

    Swift

    public var url: URL? { get }
  • 转换为文件URL

    Declaration

    Swift

    public var fileURL: URL { get }
  • 转换为NSNumber

    Declaration

    Swift

    public var number: NSNumber? { get }
  • 计算长度,中文为1,英文为0.5,表情为2

    Declaration

    Swift

    public var unicodeLength: Int { get }
  • 截取字符串,中文为1,英文为0.5,表情为2

    Declaration

    Swift

    public func unicodeSubstring(_ length: Int) -> String
  • 从指定位置截取子串

    Declaration

    Swift

    public func substring(from index: Int) -> String
  • 截取子串到指定位置

    Declaration

    Swift

    public func substring(to index: Int) -> String
  • 截取指定范围的子串

    Declaration

    Swift

    public func substring(with range: NSRange) -> String
  • 截取指定范围的子串

    Declaration

    Swift

    public func substring(with range: Range<Int>) -> String

Available where Base: NSNumber

  • 安全数字,不为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

Available where Base == URL

  • 安全URL,不为nil,不兼容文件路径(需fileURLWithPath)

    Declaration

    Swift

    public static func safeURL(_ value: Any?) -> URL
  • 生成URL,中文自动URL编码

    Declaration

    Swift

    public static func url(string: String?) -> URL?
  • 生成URL,中文自动URL编码,支持基准URL

    Declaration

    Swift

    public static func url(string: String?, relativeTo baseURL: URL?) -> URL?

Exchange

  • 交换类实例方法。复杂情况可能会冲突

    Declaration

    Swift

    @discardableResult
    public static func exchangeInstanceMethod(
        _ originalClass: AnyClass,
        originalSelector: Selector,
        swizzleSelector: Selector
    ) -> Bool

    Parameters

    originalClass

    目标类

    originalSelector

    原始方法

    swizzleSelector

    交换方法

    Return Value

    是否成功

  • 交换类静态方法。复杂情况可能会冲突

    Declaration

    Swift

    @discardableResult
    public static func exchangeClassMethod(
        _ originalClass: AnyClass,
        originalSelector: Selector,
        swizzleSelector: Selector
    ) -> Bool

    Parameters

    originalClass

    目标类

    originalSelector

    原始方法

    swizzleSelector

    交换方法

    Return Value

    是否成功

  • 交换类实例方法为block实现。复杂情况可能会冲突

    swizzleBlock示例:

    ^(__unsafe_unretained UIViewController *selfObject, BOOL animated){ ((void(*)(id, SEL, BOOL))objc_msgSend)(selfObject, swizzleSelector, animated); }
    

    Declaration

    Swift

    @discardableResult
    public static func exchangeInstanceMethod(
        _ originalClass: AnyClass,
        originalSelector: Selector,
        swizzleSelector: Selector,
        block: Any
    ) -> Bool

    Parameters

    originalClass

    目标类

    originalSelector

    原始方法

    swizzleSelector

    交换方法

    block

    实现block

    Return Value

    是否成功

  • 交换类静态方法为block实现。复杂情况可能会冲突

    Declaration

    Swift

    @discardableResult
    public static func exchangeClassMethod(
        _ originalClass: AnyClass,
        originalSelector: Selector,
        swizzleSelector: Selector,
        block: Any
    ) -> Bool

    Parameters

    originalClass

    目标类

    originalSelector

    原始方法

    swizzleSelector

    交换方法

    block

    实现block

    Return Value

    是否成功

  • 生成原始方法对应的随机交换方法

    Declaration

    Swift

    public static func exchangeSwizzleSelector(
        _ selector: Selector
    ) -> Selector

    Parameters

    selector

    原始方法

    Return Value

    交换方法

SwizzleStore

  • 通用swizzle替换方法为block实现,支持类和对象,identifier有值且相同时仅执行一次。复杂情况不会冲突,推荐使用

    Swift实现代码示例:

    NSObject.fw.swizzleMethod(
        UIViewController.self,
        selector: #selector(UIViewController.viewDidLoad)
    ) { (store: SwizzleStore
         <@convention(c) (UIViewController, Selector) -> Void,
         @convention(block) (UIViewController) -> Void>) in {
        store.original($0, store.selector)
        // ...
    }}
    

    Declaration

    Swift

    @discardableResult
    public static func swizzleMethod<MethodSignature, SwizzleSignature>(
        _ target: Any?,
        selector: Selector,
        identifier: String? = nil,
        methodSignature: MethodSignature.Type = MethodSignature.self,
        swizzleSignature: SwizzleSignature.Type = SwizzleSignature.self,
        block: @escaping (SwizzleStore<MethodSignature, SwizzleSignature>) -> SwizzleSignature
    ) -> Bool

    Parameters

    target

    目标类或对象

    selector

    原始方法

    identifier

    唯一标识,有值且相同时仅执行一次,默认nil

    methodSignature

    原始方法签名,示例:(@convention© (AnyObject, Selector) -> String).self

    swizzleSignature

    交换方法签名,示例:(@convention(block) (AnyObject) -> String).self

    block

    实现句柄,示例:{ store in { selfObject in return store.original(selfObject, store.selector) } }

    Return Value

    是否成功

  • 使用swizzle替换类实例方法为block实现,identifier有值且相同时仅执行一次。复杂情况不会冲突,推荐使用

    Swift实现代码示例:

    NSObject.fw.swizzleInstanceMethod(
        UIViewController.self,
        selector: #selector(UIViewController.viewDidLoad),
        methodSignature: (@convention(c) (UIViewController, Selector) -> Void).self,
        swizzleSignature: (@convention(block) (UIViewController) -> Void).self
    ) { store in { selfObject in
        store.original(selfObject, store.selector)
        // ...
    }}
    

    Declaration

    Swift

    @discardableResult
    public static func swizzleInstanceMethod<MethodSignature, SwizzleSignature>(
        _ originalClass: AnyClass,
        selector: Selector,
        identifier: String? = nil,
        methodSignature: MethodSignature.Type = MethodSignature.self,
        swizzleSignature: SwizzleSignature.Type = SwizzleSignature.self,
        block: @escaping (SwizzleStore<MethodSignature, SwizzleSignature>) -> SwizzleSignature
    ) -> Bool

    Parameters

    originalClass

    原始类

    selector

    原始方法

    identifier

    唯一标识,默认nil

    methodSignature

    原始方法签名,示例:(@convention© (AnyObject, Selector) -> String).self

    swizzleSignature

    交换方法签名,示例:(@convention(block) (AnyObject) -> String).self

    block

    实现句柄,示例:{ store in { selfObject in return store.original(selfObject, store.selector) } }

    Return Value

    是否成功

  • 使用swizzle替换类静态方法为block实现,identifier有值且相同时仅执行一次。复杂情况不会冲突,推荐使用

    Declaration

    Swift

    @discardableResult
    public static func swizzleClassMethod<MethodSignature, SwizzleSignature>(
        _ originalClass: AnyClass,
        selector: Selector,
        identifier: String? = nil,
        methodSignature: MethodSignature.Type = MethodSignature.self,
        swizzleSignature: SwizzleSignature.Type = SwizzleSignature.self,
        block: @escaping (SwizzleStore<MethodSignature, SwizzleSignature>) -> SwizzleSignature
    ) -> Bool

    Parameters

    originalClass

    原始类

    selector

    原始方法

    identifier

    唯一标识,默认nil

    methodSignature

    原始方法签名,示例:(@convention© (AnyObject, Selector) -> String).self

    swizzleSignature

    交换方法签名,示例:(@convention(block) (AnyObject) -> String).self

    block

    实现句柄,示例:{ store in { selfObject in return store.original(selfObject, store.selector) } }

    Return Value

    是否成功

  • 使用swizzle替换对象实例方法为block实现,identifier相同时仅执行一次。结合isSwizzleInstanceMethod使用

    Declaration

    Swift

    @discardableResult
    public func swizzleInstanceMethod<MethodSignature, SwizzleSignature>(
        _ originalSelector: Selector,
        identifier: String = "",
        methodSignature: MethodSignature.Type = MethodSignature.self,
        swizzleSignature: SwizzleSignature.Type = SwizzleSignature.self,
        block: @escaping (SwizzleStore<MethodSignature, SwizzleSignature>) -> SwizzleSignature
    ) -> Bool

    Parameters

    originalSelector

    原始方法

    identifier

    唯一标识,默认空字符串

    methodSignature

    原始方法签名,示例:(@convention© (AnyObject, Selector) -> String).self

    swizzleSignature

    交换方法签名,示例:(@convention(block) (AnyObject) -> String).self

    block

    实现句柄,示例:{ store in { selfObject in return store.original(selfObject, store.selector) } }

    Return Value

    是否成功

Swizzle

  • 通用swizzle替换方法为block实现,支持类和对象,identifier有值且相同时仅执行一次。复杂情况不会冲突,推荐使用

    Swift实现代码示例:

    NSObject.fw.swizzleInstanceMethod(UIViewController.self, selector: NSSelectorFromString("viewDidLoad")) { targetClass, originalCMD, originalIMP in
        let swizzleIMP: @convention(block)(UIViewController) -> Void = { selfObject in
            let originalMSG = unsafeBitCast(originalIMP(), to: (@convention(c)(UIViewController, Selector) -> Void).self)
            originalMSG(selfObject, originalCMD)
    
            // ...
        }
        return unsafeBitCast(swizzleIMP, to: AnyObject.self)
    }
    

    Declaration

    Swift

    @discardableResult
    public static func swizzleMethod(
        _ target: Any?,
        selector: Selector,
        identifier: String? = nil,
        block: @escaping (AnyClass, Selector, @escaping () -> IMP) -> Any
    ) -> Bool

    Parameters

    target

    目标类或对象

    selector

    原始方法

    identifier

    唯一标识,有值且相同时仅执行一次,默认nil

    block

    实现句柄

    Return Value

    是否成功

  • 使用swizzle替换类实例方法为block实现,identifier有值且相同时仅执行一次。复杂情况不会冲突,推荐使用

    Swift实现代码示例:

    NSObject.fw.swizzleInstanceMethod(UIViewController.self, selector: NSSelectorFromString("viewDidLoad")) { targetClass, originalCMD, originalIMP in
        let swizzleIMP: @convention(block)(UIViewController) -> Void = { selfObject in
            let originalMSG = unsafeBitCast(originalIMP(), to: (@convention(c)(UIViewController, Selector) -> Void).self)
            originalMSG(selfObject, originalCMD)
    
            // ...
        }
        return unsafeBitCast(swizzleIMP, to: AnyObject.self)
    }
    

    Declaration

    Swift

    @discardableResult
    public static func swizzleInstanceMethod(
        _ originalClass: AnyClass,
        selector: Selector,
        identifier: String? = nil,
        block: @escaping (AnyClass, Selector, @escaping () -> IMP) -> Any
    ) -> Bool

    Parameters

    originalClass

    原始类

    selector

    原始方法

    identifier

    唯一标识,默认nil

    block

    实现句柄

    Return Value

    是否成功

  • 使用swizzle替换类静态方法为block实现,identifier有值且相同时仅执行一次。复杂情况不会冲突,推荐使用

    Declaration

    Swift

    @discardableResult
    public static func swizzleClassMethod(
        _ originalClass: AnyClass,
        selector: Selector,
        identifier: String? = nil,
        block: @escaping (AnyClass, Selector, @escaping () -> IMP) -> Any
    ) -> Bool

    Parameters

    originalClass

    原始类

    selector

    原始方法

    identifier

    唯一标识,默认nil

    block

    实现句柄

    Return Value

    是否成功

  • 使用swizzle替换对象实例方法为block实现,identifier相同时仅执行一次。结合isSwizzleInstanceMethod使用

    Declaration

    Swift

    @discardableResult
    public func swizzleInstanceMethod(
        _ originalSelector: Selector,
        identifier: String = "",
        block: @escaping (AnyClass, Selector, @escaping () -> IMP) -> Any
    ) -> Bool

    Parameters

    originalSelector

    原始方法

    identifier

    唯一标识,默认空字符串

    block

    实现句柄

    Return Value

    是否成功

  • 判断对象是否使用swizzle替换过指定identifier实例方法。结合swizzleInstanceMethod使用

    因为实际替换的是类方法,为了防止影响该类其它对象,需先判断该对象是否替换过,仅替换过才执行自定义流程

    Declaration

    Swift

    public func isSwizzleInstanceMethod(
        _ originalSelector: Selector,
        identifier: String = ""
    ) -> Bool

    Parameters

    originalSelector

    原始方法

    identifier

    唯一标识,默认空字符串

    Return Value

    是否替换

Available where Base: UINavigationController

  • 自定义转场过程中containerView的背景色,默认透明

    Declaration

    Swift

    public var containerBackgroundColor: UIColor! { get set }
  • 全局启用NavigationBar转场。启用后各个ViewController管理自己的导航栏样式,在viewDidLoad或viewViewAppear中设置即可

    Declaration

    Swift

    public static func enableBarTransition()
  • 是否启用导航栏全屏返回手势,默认NO。启用时系统返回手势失效,禁用时还原系统手势。如果只禁用系统手势,设置interactivePopGestureRecognizer.enabled即可

    Declaration

    Swift

    public var fullscreenPopGestureEnabled: Bool { get set }
  • 导航栏全屏返回手势对象

    Declaration

    Swift

    public var fullscreenPopGestureRecognizer: UIPanGestureRecognizer { get }
  • 判断手势是否是全局返回手势对象

    Declaration

    Swift

    public static func isFullscreenPopGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer) -> Bool

Available where Base: UIViewController

  • 转场动画自定义判断标识,不相等才会启用转场。默认nil启用转场。可重写或者push前设置生效

    Declaration

    Swift

    public var barTransitionIdentifier: AnyHashable? { get set }
  • 视图控制器是否禁用全屏返回手势,默认NO

    Declaration

    Swift

    public var fullscreenPopGestureDisabled: Bool { get set }
  • 视图控制器全屏手势距离左侧最大距离,默认0,无限制

    Declaration

    Swift

    public var fullscreenPopGestureDistance: CGFloat { get set }

Available where Base: UINavigationBar

  • 导航栏背景视图,显示背景色和背景图片等

    Declaration

    Swift

    public var backgroundView: UIView? { get }
  • 导航栏内容视图,iOS11+才存在,显示item和titleView等

    Declaration

    Swift

    public var contentView: UIView? { get }
  • 导航栏大标题视图,显示时才有值。如果要设置背景色,可使用backgroundView.backgroundColor

    Declaration

    Swift

    public var largeTitleView: UIView? { get }
  • 导航栏大标题高度,与是否隐藏无关

    Declaration

    Swift

    public static var largeTitleHeight: CGFloat { get }

Available where Base: UIToolbar

  • 工具栏背景视图,显示背景色和背景图片等。如果标签栏同时显示,背景视图高度也会包含标签栏高度

    Declaration

    Swift

    public var backgroundView: UIView? { get }
  • 工具栏内容视图,iOS11+才存在,显示item等

    Declaration

    Swift

    public var contentView: UIView? { get }

Available where Base: UIView

  • 显示右上角提醒灯,上右偏移指定距离(正外负内)

    Declaration

    Swift

    public func showBadgeView(_ badgeView: BadgeView, badgeValue: String? = nil)
  • 隐藏提醒灯

    Declaration

    Swift

    public func hideBadgeView()

Available where Base: UIBarItem

  • 获取UIBarItem(UIBarButtonItem、UITabBarItem)内部的view,通常对于navigationItem和tabBarItem而言,需要在设置为item后并且在bar可见时(例如 viewDidAppear:及之后)获取fwView才有值

    Declaration

    Swift

    public weak var view: UIView? { get }
  • 当item内的view生成后就会调用一次这个block,仅对UIBarButtonItem、UITabBarItem有效

    Declaration

    Swift

    public var viewLoadedBlock: ((Base, UIView) -> Void)? { get set }

Available where Base: UIBarButtonItem

  • 显示右上角提醒灯,上右偏移指定距离(正外负内)

    Declaration

    Swift

    public func showBadgeView(_ badgeView: BadgeView, badgeValue: String? = nil)
  • 隐藏提醒灯

    Declaration

    Swift

    public func hideBadgeView()

Available where Base: UITabBarItem

  • 获取一个UITabBarItem内显示图标的UIImageView,如果找不到则返回nil

    Declaration

    Swift

    public weak var imageView: UIImageView? { get }
  • 显示右上角提醒灯,上右偏移指定距离(正外负内)

    Declaration

    Swift

    public func showBadgeView(_ badgeView: BadgeView, badgeValue: String? = nil)
  • 隐藏提醒灯

    Declaration

    Swift

    public func hideBadgeView()

Available where Base: UICollectionView

  • 集合视图代理,延迟加载

    Declaration

    Swift

    public var collectionDelegate: CollectionViewDelegate { get set }
  • 快速创建collectionView

    Declaration

    Swift

    public static func collectionView() -> Base
  • 快速创建collectionView,自定义collectionViewLayout

    Declaration

    Swift

    public static func collectionView(_ collectionViewLayout: UICollectionViewLayout) -> Base

Available where Base: UICollectionViewFlowLayout

  • 初始化布局section配置,在prepareLayout调用即可

    Declaration

    Swift

    public func sectionConfigPrepareLayout()
  • 获取布局section属性,在layoutAttributesForElementsInRect:调用并添加即可

    Declaration

    Swift

    public func sectionConfigLayoutAttributes(forElementsIn rect: CGRect) -> [UICollectionViewLayoutAttributes]

Available where Base: UIView

  • 抽屉拖拽视图,绑定抽屉拖拽效果后才存在

    Declaration

    Swift

    public var drawerView: DrawerView? { get set }
  • 设置抽屉拖拽效果。如果view为滚动视图,自动处理与滚动视图pan手势冲突的问题

    @param direction 拖拽方向,如向上拖动视图时为Up,默认向上 @param positions 抽屉位置,至少两级,相对于view父视图的originY位置 @param kickbackHeight 回弹高度,拖拽小于该高度执行回弹 @param positionChanged 抽屉视图位移回调,参数为相对父视图的origin位置和是否拖拽完成的标记 @return 抽屉拖拽视图

    Declaration

    Swift

    @discardableResult
    public func drawerView(
        _ direction: UISwipeGestureRecognizer.Direction,
        positions: [CGFloat],
        kickbackHeight: CGFloat,
        positionChanged: ((CGFloat, Bool) -> Void)? = nil
    ) -> DrawerView

Available where Base: UIScrollView

  • 外部滚动视图是否位于顶部固定位置,在顶部时不能滚动

    Declaration

    Swift

    public var drawerSuperviewFixed: Bool { get set }
  • 外部滚动视图scrollViewDidScroll调用,参数为固定的位置

    Declaration

    Swift

    public func drawerSuperviewDidScroll(_ position: CGFloat)
  • 内嵌滚动视图scrollViewDidScroll调用,参数为外部滚动视图

    Declaration

    Swift

    public func drawerSubviewDidScroll(_ superview: UIScrollView)

Available where Base: UIView

  • 视图持有者对象,弱引用

    Declaration

    Swift

    public weak var viewHolder: NSObject? { get set }
  • 重用唯一标志,默认nil

    Declaration

    Swift

    public var reuseIdentifier: String? { get set }
  • 视图已重用次数,默认0

    Declaration

    Swift

    public var reusedTimes: Int { get set }
  • 标记重用准备中(true),准备中的视图在完成(false)之前都不会被dequeue,默认false

    Declaration

    Swift

    public var reusePreparing: Bool { get set }
  • 标记重用失效,将自动从缓存池移除

    Declaration

    Swift

    public var reuseInvalid: Bool { get set }
  • 按需预加载下一个可重用视图,仅当前视图可重用时生效

    Declaration

    Swift

    public func preloadReusableView()

Available where Base: UITableView

  • 表格代理,延迟加载

    Declaration

    Swift

    public var tableDelegate: TableViewDelegate { get set }
  • 快速创建tableView,可配置钩子句柄

    Declaration

    Swift

    public static func tableView(_ style: UITableView.Style = .plain) -> Base
  • 配置创建tableView钩子句柄,默认nil

    Declaration

    Swift

    public static var tableViewConfiguration: ((Base) -> Void)? { get set }

Available where Base: UIScrollView

Available where Base: UITextField

Available where Base: UITextView

Available where Base: UISearchBar

Available where Base: UIViewController

  • 视图控制器present|dismiss转场。注意会修改transitioningDelegate,且会强引用之;如需weak引用,请直接设置transitioningDelegate

    Declaration

    Swift

    public var modalTransition: AnimatedTransition? { get set }
  • 视图控制器push|pop转场,代理导航控制器转场,需在fwNavigationTransition设置后生效

    Declaration

    Swift

    public var viewTransition: AnimatedTransition? { get set }
  • 自定义控制器present系统转场(蒙层渐变,内容默认向上动画),会设置fwModalTransition

    Declaration

    Swift

    @discardableResult
    public func setPresentTransition(_ presentationBlock: ((PresentationController) -> Void)? = nil, edge: UIRectEdge = .bottom) -> AnimatedTransition
  • 自定义控制器alert缩放转场(蒙层渐变,内容缩放动画),会设置fwModalTransition

    Declaration

    Swift

    @discardableResult
    public func setAlertTransition(_ presentationBlock: ((PresentationController) -> Void)? = nil) -> AnimatedTransition
  • 自定义控制器fade渐变转场(蒙层和内容渐变动画),会设置fwModalTransition;

    Declaration

    Swift

    @discardableResult
    public func setFadeTransition(_ presentationBlock: ((PresentationController) -> Void)? = nil) -> AnimatedTransition
  • 设置iOS13默认present手势下拉dismiss时的回调block,仅iOS13生效,自动触发,手工dismiss不会触发。会自动设置presentationController.delegate

    Declaration

    Swift

    public var presentationDidDismiss: (() -> Void)? { get set }
  • 自定义控制器popover弹出效果(preferredContentSize设置大小),会自动设置modalPresentationStyle和popoverPresentationController.delegate

    Declaration

    Swift

    public func setPopoverPresentation(_ presentationBlock: ((UIPopoverPresentationController) -> Void)?, shouldDismiss: Bool)

Available where Base: UIView

  • 转场添加到指定控制器(pinEdges占满父视图),返回父容器视图。VC.tabBarController.view > VC.navigationController.view > VC.view

    Declaration

    Swift

    @discardableResult
    public func transition(to viewController: UIViewController, pinEdges aPinEdges: Bool = true) -> UIView
  • 包装到转场控制器(pinEdges占满父视图),返回创建的控制器

    Declaration

    Swift

    public func wrappedTransitionController(_ aPinEdges: Bool = true) -> UIViewController
  • 自定义视图模拟present系统转场(蒙层渐变,内容默认向上动画)

    Declaration

    Swift

    public func setPresentTransition(_ transitionType: AnimatedTransitionType, contentView: UIView?, edge: UIRectEdge = .bottom, completion: ((Bool) -> Void)? = nil)
  • 自定义视图模拟alert缩放转场(蒙层渐变,内容缩放动画)

    Declaration

    Swift

    public func setAlertTransition(_ transitionType: AnimatedTransitionType, completion: ((Bool) -> Void)? = nil)
  • 自定义视图模拟fade渐变转场(蒙层和内容渐变动画)

    Declaration

    Swift

    public func setFadeTransition(_ transitionType: AnimatedTransitionType, completion: ((Bool) -> Void)? = nil)

Available where Base: UINavigationController

  • 导航控制器push|pop转场。注意会修改delegate,且会强引用之,一直生效直到设置为nil。如需weak引用,请直接设置delegate

    Declaration

    Swift

    public var navigationTransition: AnimatedTransition? { get set }

Available where Base: WKWebView

  • 重用WebView全局配置句柄(第二个参数为重用标志),为所有复用WebView提供预先的默认configuration

    Declaration

    Swift

    public static var reuseConfigurationBlock: ((WKWebViewConfiguration, String) -> Void)? { get set }
  • 默认跨WKWebView共享Cookie,切换用户时可重置processPool清空Cookie

    Declaration

    Swift

    public static var processPool: WKProcessPool { get set }
  • 快捷创建WKWebView默认配置,自动初始化User-Agent和共享processPool

    Declaration

    Swift

    public static func defaultConfiguration() -> WKWebViewConfiguration
  • 获取默认浏览器UserAgent,包含应用信息,示例:Mozilla/5.0 (iPhone; CPU OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Safari/605.1.15 Example/1.0.0

    Declaration

    Swift

    public static var browserUserAgent: String { get }
  • 获取默认浏览器扩展UserAgent,不含平台信息,可用于applicationNameForUserAgent,示例:Mobile/15E148 Safari/605.1.15 Example/1.0.0

    Declaration

    Swift

    public static var extensionUserAgent: String { get }
  • 获取默认请求UserAgent,可用于网络请求,示例:Example/1.0.0 (iPhone; iOS 14.2; Scale/3.00)

    Declaration

    Swift

    public static var requestUserAgent: String { get }
  • 获取当前UserAgent,未自定义时为默认,示例:Mozilla/5.0 (iPhone; CPU OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

    Declaration

    Swift

    public var userAgent: String { get }
  • 加载网页请求,支持String|URL|URLRequest等

    Declaration

    Swift

    @discardableResult
    public func loadRequest(_ request: Any?) -> WKNavigation?
  • 清空网页缓存,完成后回调。单个网页请求指定URLRequest.cachePolicy即可

    Declaration

    Swift

    public static func clearCache(_ completion: (() -> Void)? = nil)
  • 清空WebView后退和前进的网页栈

    Declaration

    Swift

    public func clearBackForwardList()
  • 使用JavaScriptCore执行脚本并返回结果,支持模板替换。常用语服务端下发计算公式等场景

    Declaration

    Swift

    public static func evaluateScript(_ script: String, variables: [String : String] = [:]) -> JSValue?
  • 设置Javascript桥接器强引用属性,防止使用过程中被释放

    Declaration

    Swift

    public var jsBridge: WebViewJSBridge? { get set }
  • 是否启用Javascript桥接器,需结合setupJsBridge使用

    Declaration

    Swift

    public var jsBridgeEnabled: Bool { get set }
  • 自动初始化Javascript桥接器,jsBridgeEnabled开启时生效

    Declaration

    Swift

    @discardableResult
    public func setupJsBridge() -> WebViewJSBridge?
  • 绑定控制器导航栏左侧按钮组,需结合setupNavigationItems使用

    Declaration

    Swift

    public var navigationItems: [Any]? { get set }
  • 自动初始化控制器导航栏左侧按钮组,navigationItems设置后生效

    Declaration

    Swift

    public func setupNavigationItems(_ viewController: UIViewController)

Available where Base: UIProgressView

  • 设置Web加载进度,0和1自动切换隐藏。可设置trackTintColor为clear,隐藏背景色

    Declaration

    Swift

    public var webProgress: Float { get set }

Available where Base: UIViewController

Available where Base: UIView

Available where Base: UIAlertAction

Available where Base: UIAlertController

Available where Base: UIView

Available where Base: UIViewController

Available where Base: UIScrollView

  • 空界面代理,默认nil。DZNEmptyDataSet

    Declaration

    Swift

    public weak var emptyViewDelegate: EmptyViewDelegate? { get set }
  • 刷新空界面

    Declaration

    Swift

    public func reloadEmptyView()
  • 当前数据总条数,默认自动调用tableView和collectionView的dataSource,支持自定义覆盖(优先级高,小于0还原)

    注意:此处为当前数据源总数,并非当前cell总数,即使tableView未reloadData也会返回新总数

    Declaration

    Swift

    public var totalDataCount: Int { get set }
  • 滚动视图自定义浮层,用于显示空界面等,兼容UITableView|UICollectionView

    Declaration

    Swift

    public var overlayView: UIView { get }
  • 是否显示自定义浮层

    Declaration

    Swift

    public var hasOverlayView: Bool { get }
  • 显示自定义浮层,默认不执行渐变动画,自动添加到滚动视图顶部、表格视图底部

    Declaration

    Swift

    public func showOverlayView(animated: Bool = false)
  • 隐藏自定义浮层,自动从滚动视图移除

    Declaration

    Swift

    public func hideOverlayView()

Available where Base: UIImage

  • 根据名称从指定bundle加载UIImage,优先加载图片文件(无缓存),文件不存在时尝试系统imageNamed方式(有缓存)。支持设置图片解码选项

    Declaration

    Swift

    public static func imageNamed(_ name: String, bundle: Bundle? = nil, options: [ImageCoderOptions : Any]? = nil) -> UIImage?
  • 从图片文件路径解码创建UIImage,自动识别scale,支持动图

    Declaration

    Swift

    public static func image(contentsOfFile path: String) -> UIImage?
  • 从图片数据解码创建UIImage,默认scale为1,支持动图。支持设置图片解码选项

    Declaration

    Swift

    public static func image(data: Data?, scale: CGFloat = 1, options: [ImageCoderOptions : Any]? = nil) -> UIImage?
  • 从UIImage编码创建图片数据,支持动图。支持设置图片编码选项

    Declaration

    Swift

    public static func data(image: UIImage?, options: [ImageCoderOptions : Any]? = nil) -> Data?
  • 下载网络图片并返回下载凭据,指定option

    Declaration

    Swift

    @discardableResult
    public static func downloadImage(_ url: URLParameter?, options: WebImageOptions = [], context: [ImageCoderOptions : Any]? = nil, completion: @escaping (UIImage?, Data?, Error?) -> Void, progress: ((Double) -> Void)? = nil) -> Any?
  • 指定下载凭据取消网络图片下载

    Declaration

    Swift

    public static func cancelImageDownload(_ receipt: Any?)

Available where Base: UIView

  • 自定义图片插件,未设置时自动从插件池加载

    Declaration

    Swift

    public var imagePlugin: ImagePlugin? { get set }
  • 当前正在加载的网络图片URL

    Declaration

    Swift

    public var imageURL: URL? { get }
  • 加载网络图片内部方法,支持占位、选项、图片句柄、回调和进度,优先加载插件,默认使用框架网络库

    Declaration

    Swift

    public func setImage(url: URLParameter?, placeholderImage: UIImage?, options: WebImageOptions, context: [ImageCoderOptions : Any]?, setImageBlock: ((UIImage?) -> Void)?, completion: ((UIImage?, Error?) -> Void)?, progress: ((Double) -> Void)?)
  • 取消加载网络图片请求

    Declaration

    Swift

    public func cancelImageRequest()
  • 加载指定URL的本地缓存图片

    Declaration

    Swift

    public func loadImageCache(url: URLParameter?) -> UIImage?
  • 是否隐藏全局图片加载指示器,默认false,仅全局图片指示器开启时生效

    Declaration

    Swift

    public var hidesImageIndicator: Bool { get set }

Available where Base: UIImageView

Available where Base: UIButton

Available where Base: UIImage

Available where Base: PHPhotoLibrary

  • 快速创建照片选择器(仅图片)

    @param selectionLimit 最大选择数量,iOS14以下只支持单选 @param allowsEditing 是否允许编辑,仅iOS14以下支持编辑 @param completion 完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消 @return 照片选择器

    Declaration

    Swift

    public static func pickerController(selectionLimit: Int, allowsEditing: Bool, completion: @escaping ([UIImage], [Any], Bool) -> Void) -> UIViewController?
  • 快速创建照片选择器,可自定义dismiss流程

    @param filterType 过滤类型,默认0同系统 @param selectionLimit 最大选择数量,iOS14以下只支持单选 @param allowsEditing 是否允许编辑,仅iOS14以下支持编辑 @param shouldDismiss 是否先关闭照片选择器再回调,如果先关闭则回调参数1为nil @param completion 完成回调,主线程。参数1为照片选择器,2为对象数组(UIImage|PHLivePhoto|NSURL),3位结果数组,4为是否取消 @return 照片选择器

    Declaration

    Swift

    public static func pickerController(filterType: ImagePickerFilterType, selectionLimit: Int, allowsEditing: Bool, shouldDismiss: Bool, completion: @escaping (UIViewController?, [Any], [Any], Bool) -> Void) -> UIViewController?
  • 快速创建照片选择器(仅图片),使用自定义裁剪控制器编辑

    @param selectionLimit 最大选择数量 @param cropController 自定义裁剪控制器句柄,nil时自动创建默认裁剪控制器 @param completion 完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消 @return 照片选择器

    Declaration

    Swift

    public static func pickerController(selectionLimit: Int, cropController: ((UIImage) -> ImageCropController)?, completion: @escaping ([UIImage], [Any], Bool) -> Void) -> UIViewController?

Available where Base: UIViewController

  • 自定义图片选取插件,未设置时自动从插件池加载

    Declaration

    Swift

    public var imagePickerPlugin: ImagePickerPlugin! { get set }
  • 从Camera选取单张图片(简单版)

    Declaration

    Swift

    public func showImageCamera(allowsEditing: Bool, completion: @escaping (UIImage?, Bool) -> Void)

    Parameters

    allowsEditing

    是否允许编辑

    completion

    完成回调,主线程。参数1为图片,2为是否取消

  • 从Camera选取单张图片(详细版)

    Declaration

    Swift

    public func showImageCamera(filterType: ImagePickerFilterType, allowsEditing: Bool, customBlock: ((Any) -> Void)? = nil, completion: @escaping (Any?, Any?, Bool) -> Void)

    Parameters

    filterType

    过滤类型,默认0同系统

    allowsEditing

    是否允许编辑

    customBlock

    自定义配置句柄,默认nil

    completion

    完成回调,主线程。参数1为对象(UIImage|PHLivePhoto|NSURL),2为结果信息,3为是否取消

  • 从图片库选取单张图片(简单版)

    Declaration

    Swift

    public func showImagePicker(allowsEditing: Bool, completion: @escaping (UIImage?, Bool) -> Void)

    Parameters

    allowsEditing

    是否允许编辑

    completion

    完成回调,主线程。参数1为图片,2为是否取消

  • 从图片库选取多张图片(简单版)

    Declaration

    Swift

    public func showImagePicker(selectionLimit: Int, allowsEditing: Bool, completion: @escaping ([UIImage], [Any], Bool) -> Void)

    Parameters

    selectionLimit

    最大选择数量

    allowsEditing

    是否允许编辑

    completion

    完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消

  • 从图片库选取多张图片(详细版)

    Declaration

    Swift

    public func showImagePicker(filterType: ImagePickerFilterType, selectionLimit: Int, allowsEditing: Bool, customBlock: ((Any) -> Void)? = nil, completion: @escaping ([Any], [Any], Bool) -> Void)

    Parameters

    filterType

    过滤类型,默认0同系统

    selectionLimit

    最大选择数量

    allowsEditing

    是否允许编辑

    customBlock

    自定义配置句柄,默认nil

    completion

    完成回调,主线程。参数1为对象数组(UIImage|PHLivePhoto|NSURL),2位结果数组,3为是否取消

Available where Base: UIView

  • 从Camera选取单张图片(简单版)

    Declaration

    Swift

    public func showImageCamera(allowsEditing: Bool, completion: @escaping (UIImage?, Bool) -> Void)

    Parameters

    allowsEditing

    是否允许编辑

    completion

    完成回调,主线程。参数1为图片,2为是否取消

  • 从Camera选取单张图片(详细版)

    Declaration

    Swift

    public func showImageCamera(filterType: ImagePickerFilterType, allowsEditing: Bool, customBlock: ((Any) -> Void)? = nil, completion: @escaping (Any?, Any?, Bool) -> Void)

    Parameters

    filterType

    过滤类型,默认0同系统

    allowsEditing

    是否允许编辑

    customBlock

    自定义配置句柄,默认nil

    completion

    完成回调,主线程。参数1为对象(UIImage|PHLivePhoto|NSURL),2为结果信息,3为是否取消

  • 从图片库选取单张图片(简单版)

    Declaration

    Swift

    public func showImagePicker(allowsEditing: Bool, completion: @escaping (UIImage?, Bool) -> Void)

    Parameters

    allowsEditing

    是否允许编辑

    completion

    完成回调,主线程。参数1为图片,2为是否取消

  • 从图片库选取多张图片(简单版)

    Declaration

    Swift

    public func showImagePicker(selectionLimit: Int, allowsEditing: Bool, completion: @escaping ([UIImage], [Any], Bool) -> Void)

    Parameters

    selectionLimit

    最大选择数量

    allowsEditing

    是否允许编辑

    completion

    完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消

  • 从图片库选取多张图片(详细版)

    Declaration

    Swift

    public func showImagePicker(filterType: ImagePickerFilterType, selectionLimit: Int, allowsEditing: Bool, customBlock: ((Any) -> Void)? = nil, completion: @escaping ([Any], [Any], Bool) -> Void)

    Parameters

    filterType

    过滤类型,默认0同系统

    selectionLimit

    最大选择数量

    allowsEditing

    是否允许编辑

    customBlock

    自定义配置句柄,默认nil

    completion

    完成回调,主线程。参数1为对象数组(UIImage|PHLivePhoto|NSURL),2位结果数组,3为是否取消

Available where Base: UIImagePickerController

  • 快速创建单选照片选择器(仅图片),自动设置delegate

    @param sourceType 选择器类型 @param allowsEditing 是否允许编辑 @param completion 完成回调。参数1为图片,2为信息字典,3为是否取消 @return 照片选择器,不支持的返回nil

    Declaration

    Swift

    public static func pickerController(sourceType: UIImagePickerController.SourceType, allowsEditing: Bool, completion: @escaping (UIImage?, [AnyHashable : Any]?, Bool) -> Void) -> UIImagePickerController?
  • 快速创建单选照片选择器,可自定义dismiss流程,自动设置delegate

    @param sourceType 选择器类型 @param filterType 过滤类型,默认0同系统 @param allowsEditing 是否允许编辑 @param shouldDismiss 是否先关闭照片选择器再回调,如果先关闭则回调参数1为nil @param completion 完成回调。参数1为照片选择器,2为对象(UIImage|PHLivePhoto|NSURL),3为信息字典,4为是否取消 @return 照片选择器,不支持的返回nil

    Declaration

    Swift

    public static func pickerController(sourceType: UIImagePickerController.SourceType, filterType: ImagePickerFilterType, allowsEditing: Bool, shouldDismiss: Bool, completion: @escaping (UIImagePickerController?, Any?, [AnyHashable : Any]?, Bool) -> Void) -> UIImagePickerController?
  • 快速创建单选照片选择器,使用自定义裁剪控制器编辑

    @param sourceType 选择器类型 @param cropController 自定义裁剪控制器句柄,nil时自动创建默认裁剪控制器 @param completion 完成回调。参数1为图片,2为信息字典,3为是否取消 @return 照片选择器,不支持的返回nil

    Declaration

    Swift

    public static func pickerController(sourceType: UIImagePickerController.SourceType, cropController cropControllerBlock: ((UIImage) -> ImageCropController)?, completion: @escaping (UIImage?, [AnyHashable : Any]?, Bool) -> Void) -> UIImagePickerController?

Available where Base: PHPickerViewController

  • 快速创建多选照片选择器(仅图片),自动设置delegate

    @param selectionLimit 最大选择数量 @param completion 完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消 @return 照片选择器

    Declaration

    Swift

    public static func pickerController(selectionLimit: Int, completion: @escaping ([UIImage], [PHPickerResult], Bool) -> Void) -> PHPickerViewController
  • 快速创建多选照片选择器,可自定义dismiss流程,自动设置delegate @note 当选择视频时,completion回调对象为NSURL临时文件路径,使用完毕后可手工删除或等待系统自动删除

    @param filterType 过滤类型,默认0同系统 @param selectionLimit 最大选择数量 @param shouldDismiss 是否先关闭照片选择器再回调,如果先关闭则回调参数1为nil @param completion 完成回调,主线程。参数1为照片选择器,2为对象数组(UIImage|PHLivePhoto|NSURL),3为结果数组,4为是否取消 @return 照片选择器

    Declaration

    Swift

    public static func pickerController(filterType: ImagePickerFilterType, selectionLimit: Int, shouldDismiss: Bool, completion: @escaping (PHPickerViewController?, [Any], [PHPickerResult], Bool) -> Void) -> PHPickerViewController
  • 快速创建照片选择器(仅图片),使用自定义裁剪控制器编辑

    @param selectionLimit 最大选择数量 @param cropController 自定义裁剪控制器句柄,nil时自动创建默认裁剪控制器 @param completion 完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消 @return 照片选择器

    Declaration

    Swift

    public static func pickerController(selectionLimit: Int, cropController cropControllerBlock: ((UIImage) -> ImageCropController)?, completion: @escaping ([UIImage], [PHPickerResult], Bool) -> Void) -> PHPickerViewController
  • 自定义全局PHPickerConfiguration创建句柄,默认nil

    Declaration

    Swift

    public static var pickerConfigurationBlock: (() -> PHPickerConfiguration)? { get set }
  • 照片选择器是否已经dismiss,用于解决didFinishPicking回调多次问题

    Declaration

    Swift

    public var pickerControllerDismissed: Bool { get set }
  • 自定义照片选择器导出进度句柄,主线程回调,默认nil

    Declaration

    Swift

    public var exportProgressBlock: ((_ picker: PHPickerViewController, _ finishedCount: Int, _ totalCount: Int) -> Void)? { get set }

Available where Base: UIViewController

  • 自定义图片预览插件,未设置时自动从插件池加载

    Declaration

    Swift

    public var imagePreviewPlugin: ImagePreviewPlugin! { get set }
  • 显示图片预览(简单版)

    Declaration

    Swift

    public func showImagePreview(imageURLs: [Any], imageInfos: [Any]? = nil, currentIndex: Int = 0, sourceView: ((Int) -> Any?)? = nil)

    Parameters

    imageURLs

    预览图片列表,支持NSString|UIImage|PHLivePhoto|AVPlayerItem类型

    imageInfos

    自定义图片信息数组

    currentIndex

    当前索引,默认0

    sourceView

    来源视图,可选,支持UIView|NSValue.CGRect,默认nil

  • 显示图片预览(详细版)

    Declaration

    Swift

    public func showImagePreview(imageURLs: [Any], imageInfos: [Any]?, currentIndex: Int, sourceView: ((Int) -> Any?)?, placeholderImage: ((Int) -> UIImage?)?, renderBlock: ((UIView, Int) -> Void)? = nil, customBlock: ((Any) -> Void)? = nil)

    Parameters

    imageURLs

    预览图片列表,支持NSString|UIImage|PHLivePhoto|AVPlayerItem类型

    imageInfos

    自定义图片信息数组

    currentIndex

    当前索引,默认0

    sourceView

    来源视图句柄,支持UIView|NSValue.CGRect,默认nil

    placeholderImage

    占位图或缩略图句柄,默认nil

    renderBlock

    自定义渲染句柄,默认nil

    customBlock

    自定义句柄,默认nil

Available where Base: UIView