0
我正在嘗試對Parse中已存儲在覈心數據中的數據進行更改。但它沒有做出必要的修改。我在這裏查看關於對象的解析文檔:https://parse.com/docs/ios/guide#objects。而且我似乎正在做文件告訴我要做的事情。也許我錯過了什麼?這是我的代碼:解析不更新核心數據Swift
import UIKit
import Parse
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var products = PFObject(className:"Products")
products["name"] = "ice cream"
products["description"] = "Strawberry"
products["price"] = 4.99
products.saveInBackgroundWithBlock {
(success, error) -> Void in
if (success) {
println("Object saved with id \(products.objectId)")
} else {
println("Not successful!")
print(error)
}
}
//ignore the code below this line for now please :)
var query = PFQuery(className: "Products")
query.getObjectInBackgroundWithId("7lmnxHxibK", block: { (object: PFObject?, error) -> Void in
if error != nil {
print(error)
} else if let product = object {
print("YO")
product["description"] = "Rocky Road"
product["price"] = 5.99
products.saveInBackground()
}
})
}
}
因此,上面的代碼創建了一個ID爲7lmnxHxibK
的對象。 description
是Strawberry
,name
是ice cream
,並且price
是4.99
。它應該如此。所以現在作爲一個嘗試與ID 7lmnxHxibK
改變對象的屬性,我寫了下面的代碼:
var query = PFQuery(className: "Products")
query.getObjectInBackgroundWithId("7lmnxHxibK", block: { (object: PFObject?, error) -> Void in
if error != nil {
print(error)
} else if let product = object {
print("YO")
product["description"] = "Rocky Road"
product["price"] = 5.99
products.saveInBackground()
}
})
此代碼應該對象進行必要的修改id爲7lmnxHxibK
。但不是對對象的屬性進行必要的更改,而是創建一個新對象,其中包括description
,name
和price
,全部爲(undefined)
。任何人都有解決方案來解決這個問題?
呵呵,你在關注Rob Percival的課程嗎? –
只是爲了確保,你正試圖編輯這個'對象',在這種情況下,草莓冰淇淋是正確的? –
哈哈,是的,我是。你還好嗎?如果是這樣,你怎麼看待它? – Jae