您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页112课:用 LeanCloud 读取、更新数据

112课:用 LeanCloud 读取、更新数据

来源:二三四教育网

Section 8 主要的内容是克隆 Instagram:107 - 128课。

本节课程继续 110 课程的工程,学习用 LeanCloud 读取、更新、删除数据。

1、�读取数据的方法

let mQuery:AVQuery = AVQuery(className: 某某字符串)
mQuery.findObjectsInBackgroundWithBlock { (objects, error) in
    if error != nil {
        print(error)
    } else {
        // 这里读取出数值来了,可以在这里进行处理
        print(objects)
        // 查询某个键的值
        print(objects!.objectForKey("Detail"))
    }
)}

2、�更新数据的方法

更新数据首先要确保你更新的这条数据实际上是存在的,才能进行更新。

let query = AVQuery(className: Products)
query.getObjectInBackgroundWithId("558e20cbe4b060308e3eb36c", block: { (object: PFObject?, error: NSError? ) -> Void in
    // object 就是 id 为 558e20cbe4b060308e3eb36c 的 Products 对象实例
    if error != nil {
        print(error)   
    } else if let product = object {                
        product["description"] = "Rocky Road"                
        product["price"] = 5.99                
        product.saveInBackground()            
        print(object!.objectForKey("description"))                
    }          
})

当然,你需要知道 ID,如果不知道 ID 如何更新数据?下一节课讲。。。。

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务