当前位置: 首页 > 工具软件 > ReactiveObjC > 使用案例 >

关于ReactiveObjC和ReactiveSwift 系统通知在swift中的用法

查飞星
2023-12-01

注意观察forName属性,如果用swift 的语法UIResponder.keyboardWillShowNotification不会有任何反应       

NotificationCenter.default.rac_addObserver(forName: "UIKeyboardWillShowNotification", object: nil).subscribeNext { notifation  in

            print("监听到")

        }

底层调用

- (id <NSObject>)addObserverForName:(nullable NSNotificationName)name object:(nullable id)obj queue:(nullable NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *note))block API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0));

那么用ReactiveSwift直接可调用swift的语法完美监听

NotificationCenter.default.reactive.notifications(forName: UIResponder.keyboardWillShowNotification, object: nil).observeResult { notifation in              

    print("监听到")        

        }

底层调用

open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol

 类似资料: