简体   繁体   English

如何观察Backendless数据库的属性变化? - 斯威夫特

[英]how to observe property changes of Backendless database ? - Swift

I have this code in Swift 3 to get backendless user so I can get his/her properties: 我在Swift 3中有这个代码来获得后端用户所以我可以得到他/她的属性:

            let whereClause = "objectId = '\(userId)'"

            let query = BackendlessDataQuery()
            query.whereClause = whereClause

            let data = Backendless.sharedInstance().persistenceService.of(BackendlessUser.ofClass())

            data?.find(query, response: { (result) in

                let user = result?.data.first as! BackendlessUser

                myLabel.text = user.getProperty("firstName") as! String

          })

The code is working fine but my question is how to observe the property changes ? 代码工作正常,但我的问题是如何观察属性的变化? is there a way if the value of property firstName changed I can update my label automatically ? 有没有办法,如果属性firstName的值改变,我可以自动更新我的标签?

The use-case you describe is not really as simple as it may seem, but it's definitely possible. 你描述的用例并不像看起来那么简单,但绝对可能。

You can capture any changes in Users table by creating an afterUpdate event handler . 您可以通过创建afterUpdate 事件处理程序来捕获Users表中的任何更改。 From there you could publish a message to some dedicated channel in messaging service . 从那里,您可以将消息发布到消息服务中的某个专用通道

At the same time, your application should be subscribed to this same channel . 同时,您的应用程序应订阅此同一频道 This way you could update your UI when the appropriate message is received. 这样,您可以在收到相应的消息时更新UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM