SwiftUI笔记
2024-10-21 13:04:03
@Published 标记对象定义的属性变更可以被监听,当对应字段变化时会触发对象 objectWillChange 通知,订阅了该属性的View也会收到值改变的通知
/// A type that publishes a property marked with an attribute.
///
/// Publishing a property with the `@Published` attribute creates a publisher of this type. You access the publisher with the `$` operator, as shown here:
///
/// class Weather {
/// @Published var temperature: Double
/// init(temperature: Double) {
/// self.temperature = temperature
/// }
/// }
///
/// let weather = Weather(temperature: 20)
/// cancellable = weather.$temperature
/// .sink() {
/// print ("Temperature now: \($0)")
/// }
/// weather.temperature = 25
///
/// // Prints:
/// // Temperature now: 20.0
/// // Temperature now: 25.0
///
@ObservedObject 和 @State 类似,需要修饰的属性需要实现了 ObservableObject
父View 以 @State 声明的属性 @State var param: DataType,可以在子View初始化的时候以 $param 给到子View,子View 通过 @Banding 关键字取得 param 数据关联,在值变化时进行相应的改变
最新文章
- centos上如何安装redis?|centos傻瓜式安装redis教程
- c# 根据配置文件路径,设置和获取config文件 appSettings 节点值
- angularjs 表单验证(不完整版)
- WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式
- 深入理解CSS网页布局-理论篇
- BI之SSAS完整实战教程2 -- 开发环境介绍及多维数据集数据源准备
- linq查询语句转mongodb
- Java字符串的那些事儿。。。。
- bzoj4709 [jsoi2011]柠檬
- 【转】K短路
- Ubuntu 12.10 安装JDK7
- Git知识总览(六) Git分支中的远程操作实践
- ubuntu常用文件搜索命令
- 编程之美2.18 数组分割 原创解O(nlogn)的时间复杂度求解:
- 堆(Heap)详解——Java实现
- logstash收集IIS日志
- Oracle11g ADG环境实施文档-1204
- Dubbo(3)Dubbo admin管理控制台
- php+layui实现图片上传与预览
- 之前专门为IE6、7开发的网站如何迁移到IE10及可能遇到的问题和相应解决方案汇总