博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通知中心 - NSNotificationCenter
阅读量:4584 次
发布时间:2019-06-09

本文共 2298 字,大约阅读时间需要 7 分钟。

---恢复内容开始---

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

---恢复内容结束---

转载于:https://www.cnblogs.com/kinghx/p/5351016.html

你可能感兴趣的文章
定时调动 (项目保留备份代码码)
查看>>
Leetcode-Divide Two Integers
查看>>
HTML 首页倒三角形导航块
查看>>
每天一道Java题[9]
查看>>
结对编程2——单元测试
查看>>
python 函数/列表的应用
查看>>
C#与MES
查看>>
LR接口测试---Java Vuser之jdbc查询(调试前)
查看>>
SQL Server 各版本安装包分享
查看>>
.net项目移植后的虚拟目录的配置问题
查看>>
JSP页面中引入另一个JSP页面
查看>>
Android笔记——活动的生命周期
查看>>
springmvc使用包装的pojo接收商品信息的查询条件
查看>>
【Linux】【Services】【Configuration】puppet
查看>>
poj 1002:487-3279(水题,提高题 / hash)
查看>>
RAC环境上搭建DG
查看>>
OS X Mountain Lion高手进阶
查看>>
精通CSS:高级Web标准解决方案(第2版)(Amazon第一CSS畅销书全新改版)
查看>>
初识电流环
查看>>
MySQL每天自动增加分区
查看>>