---恢复内容开始---
NS_ASSUME_NONNULL_BEGIN
/**************** Notifications ****************/
// 通知,被发送,被接受。
@interface NSNotification : NSObject <NSCopying, NSCoding>
通知的名字
@property (readonly, copy) NSString *name;
具体某一个对象。
@property (nullable, readonly, retain) id object;
参数信息
@property (nullable, readonly, copy) NSDictionary *userInfo;
初始化一个 通知 对象
name 将来又谁来接受,(发送给谁)
object 具体的某一个对象,或者为nil,
userInfo 附加的信息,参数
- (instancetype)initWithName:(NSString *)name object:(nullable id)object userInfo:(nullable NSDictionary *)userInfo NS_AVAILABLE(10_6, 4_0) NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
@end
@interface NSNotification (NSNotificationCreation)
初始化一个通知
+ (instancetype)notificationWithName:(NSString *)aName object:(nullable id)anObject;
同上
+ (instancetype)notificationWithName:(NSString *)aName object:(nullable id)anObject userInfo:(nullable NSDictionary *)aUserInfo;
- (instancetype)init /*NS_UNAVAILABLE*/; /* do not invoke; not a valid initializer for this class */
@end
/**************** Notification Center ****************/
@interface NSNotificationCenter : NSObject {
@package
void * __strong _impl;
void * __strong _callback;
void *_pad[11];
}
单利,获取通知中心,来注册,或者发送通知。一定是 先注册,后发送。不然,无效。
+ (NSNotificationCenter *)defaultCenter;
注册通知,(监听通知)
- (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullable NSString *)aName object:(nullable id)anObject;
发送通知
- (void)postNotification:(NSNotification *)notification;
- (void)postNotificationName:(NSString *)aName object:(nullable id)anObject;
- (void)postNotificationName:(NSString *)aName object:(nullable id)anObject userInfo:(nullable NSDictionary *)aUserInfo;
移除通知
- (void)removeObserver:(id)observer;
- (void)removeObserver:(id)observer name:(nullable NSString *)aName object:(nullable id)anObject;
- (id <NSObject>)addObserverForName:(nullable NSString *)name object:(nullable id)obj queue:(nullable NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *note))block NS_AVAILABLE(10_6, 4_0);
// The return value is retained by the system, and should be held onto by the caller in
// order to remove the observer with removeObserver: later, to stop observation.
@end
NS_ASSUME_NONNULL_END
---恢复内容结束---