ViewContext
public class ViewContext : ObservableObject
视图上下文
-
当前视图控制器
Declaration
Swift
public weak var viewController: UIViewController?
-
获取当前导航栏控制器
Declaration
Swift
@MainActor public weak var navigationController: UINavigationController? { get }
-
获取当前UIView根视图
Declaration
Swift
@MainActor public weak var hostingView: UIView? { get }
-
获取当前AnyView根视图
Declaration
Swift
@MainActor public var rootView: AnyView? { get }
-
自定义对象,自动广播,订阅方式:onReceive(viewContext.$object)
Declaration
Swift
@Published public var object: Any? { get set }
-
自定义用户信息,可初始化时设置,也可修改后手动广播
Declaration
Swift
public var userInfo: [AnyHashable : Any]?
-
上下文Subject,可订阅,需手工触发send发送广播
Declaration
Swift
public let subject: PassthroughSubject<ViewContext, Never>
-
手动发送广播,一般修改userInfo后调用
Declaration
Swift
public func send()
-
初始化方法,可指定视图控制器、自定义对象和用户信息
Declaration
Swift
public init(_ viewController: UIViewController?, object: Any? = nil, userInfo: [AnyHashable : Any]? = nil)