diff --git a/Sources/ProHUD/Alert/Alert.swift b/Sources/ProHUD/Alert/Alert.swift index b923a42..8368f99 100644 --- a/Sources/ProHUD/Alert/Alert.swift +++ b/Sources/ProHUD/Alert/Alert.swift @@ -73,10 +73,10 @@ open class Alert: ProHUD.Controller { return stack }() - open class ViewModel: BaseViewModel {} + @objc(AlertViewModel) open class ViewModel: BaseViewModel {} /// 视图模型 - public var vm = ViewModel() + @objc public var vm = ViewModel() public override var title: String? { didSet { @@ -84,7 +84,7 @@ open class Alert: ProHUD.Controller { } } - @discardableResult public init(_ vm: ViewModel, handler: ((_ alert: Alert) -> Void)? = nil) { + @discardableResult @objc public init(_ vm: ViewModel, handler: ((_ alert: Alert) -> Void)? = nil) { super.init() self.vm = vm handler?(self) @@ -96,7 +96,7 @@ open class Alert: ProHUD.Controller { } } - @discardableResult public convenience init(handler: ((_ alert: Alert) -> Void)?) { + @discardableResult @objc public convenience init(handler: ((_ alert: Alert) -> Void)?) { self.init(.init(), handler: handler) } diff --git a/Sources/ProHUD/Capsule/Capsule.swift b/Sources/ProHUD/Capsule/Capsule.swift index 059d91e..41d250b 100644 --- a/Sources/ProHUD/Capsule/Capsule.swift +++ b/Sources/ProHUD/Capsule/Capsule.swift @@ -44,14 +44,15 @@ open class Capsule: Controller { return lb }() - open class ViewModel: BaseViewModel { + @objc(CapsuleViewModel) open class ViewModel: BaseViewModel { - public enum Position { + @objc public enum Position: Int { case top case middle case bottom } - public var position: Position = .top + + @objc public var position: Position = .top public static var top: Self { let obj = Self.init() @@ -72,11 +73,11 @@ open class Capsule: Controller { } /// 视图模型 - public var vm = ViewModel() + @objc public var vm = ViewModel() private var tapActionCallback: ((_ capsule: Capsule) -> Void)? - @discardableResult public init(_ vm: ViewModel, handler: ((_ capsule: Capsule) -> Void)? = nil) { + @discardableResult @objc public init(_ vm: ViewModel, handler: ((_ capsule: Capsule) -> Void)? = nil) { super.init() self.vm = vm handler?(self) @@ -87,7 +88,7 @@ open class Capsule: Controller { } } - @discardableResult public convenience init(handler: ((_ capsule: Capsule) -> Void)?) { + @discardableResult @objc public convenience init(handler: ((_ capsule: Capsule) -> Void)?) { self.init(.init(), handler: handler) } diff --git a/Sources/ProHUD/Core/Models/BaseViewModel.swift b/Sources/ProHUD/Core/Models/BaseViewModel.swift index a7a3bde..5ff2f68 100644 --- a/Sources/ProHUD/Core/Models/BaseViewModel.swift +++ b/Sources/ProHUD/Core/Models/BaseViewModel.swift @@ -11,19 +11,19 @@ import UIKit open class BaseViewModel: NSObject { /// 图标 - open var icon: UIImage? - var iconURL: URL? + @objc open var icon: UIImage? + @objc var iconURL: URL? /// 图标旋转动画 open var rotation: Rotation? /// 标题 - open var title: String? + @objc open var title: String? /// 消息正文 - open var message: String? + @objc open var message: String? - open var tintColor: UIColor? + @objc open var tintColor: UIColor? /// 持续时间(为空代表根据场景不同的默认配置,为0代表无穷大) open var duration: TimeInterval? { @@ -32,7 +32,7 @@ open class BaseViewModel: NSObject { } } - public required override init() { + @objc public required override init() { } diff --git a/Sources/ProHUD/Sheet/Sheet.swift b/Sources/ProHUD/Sheet/Sheet.swift index 8ed9873..c35c08d 100644 --- a/Sources/ProHUD/Sheet/Sheet.swift +++ b/Sources/ProHUD/Sheet/Sheet.swift @@ -41,7 +41,7 @@ open class Sheet: Controller { } } - @discardableResult public init(handler: @escaping (_ sheet: Sheet) -> Void, onTappedBackground action: ((_ sheet: Sheet) -> Void)? = nil) { + @discardableResult @objc public init(handler: @escaping (_ sheet: Sheet) -> Void, onTappedBackground action: ((_ sheet: Sheet) -> Void)? = nil) { super.init() onTappedBackground = action diff --git a/Sources/ProHUD/Toast/Toast.swift b/Sources/ProHUD/Toast/Toast.swift index 5fe3617..11e8152 100644 --- a/Sources/ProHUD/Toast/Toast.swift +++ b/Sources/ProHUD/Toast/Toast.swift @@ -83,10 +83,10 @@ open class Toast: Controller { /// 是否可以通过手势移除(向上滑出屏幕) public var isRemovable = true - open class ViewModel: BaseViewModel {} + @objc(ToastViewModel) open class ViewModel: BaseViewModel {} /// 视图模型 - public var vm = ViewModel() + @objc public var vm = ViewModel() private var tapActionCallback: ((_ toast: Toast) -> Void)? @@ -98,7 +98,7 @@ open class Toast: Controller { } - @discardableResult public init(_ vm: ViewModel, handler: ((_ toast: Toast) -> Void)? = nil) { + @discardableResult @objc public init(_ vm: ViewModel, handler: ((_ toast: Toast) -> Void)? = nil) { super.init() self.vm = vm handler?(self) @@ -109,7 +109,7 @@ open class Toast: Controller { } } - @discardableResult public convenience init(handler: ((_ toast: Toast) -> Void)?) { + @discardableResult @objc public convenience init(handler: ((_ toast: Toast) -> Void)?) { self.init(.init(), handler: handler) }