swift3.0 中NSNotification 的使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | swift3 . 0 有很大变化,其中之一就是 NSNotification 使用跟原来不一样,以前 NSNotification name 是 String ; 3.0 中定义了一个类型 NSNotification . name ; 使用时最好定义一个 NSNotification . name 常量方便使用; 直接上代码: [ objc ] view plain copy 在 CODE 上查看代码片派生到我的代码片 //通知名称常量 let NotifyChatMsgRecv = NSNotification . Name ( rawValue : "notifyChatMsgRecv" ) //发送通知 NotificationCenter . default . post ( name : NotifyChatMsgRecv , object : nil , userInfo : notification . userInfo ) //接受通知监听 NotificationCenter . default . addObserver ( self , selector :# selector ( didMsgRecv ( notification :)), name : NotifyChatMsgRecv , object : nil ) //通知处理函数 func didMsgRecv ( notification : NSNotification ){ print ( "didMsgRecv: \( notification . userInfo )" ) } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
2015-10-09 Swift语言Storyboard教程:第一部分
2015-10-09 Swift UI开发初探
2015-10-09 iPhone应用程序开发基础之一: IBOutlet与IBAction
2015-10-09 Swift实战-小QQ(第1章):QQ登录界面
2015-10-09 Swift实战-QQ在线音乐(AppleWatch版)
2015-10-09 iOS苹果官方Demo合集
2015-10-09 Android4.3 蓝牙BLE初步