I have a column in my parse table that i want to store names in when a user accepts another user, so it is one string at a time.
The column is called "passengers" and the string I am trying to store is an Id.
I successfully get the correct Id but saving it to the column in parse is my problem.
Here is my code
var appendToPassengerArrayQuery = PFQuery(className: "Posts")
appendToPassengerArrayQuery.getObjectInBackgroundWithId(cell.postIdLabel.text!, block: {
(object:PFObject?, error: NSError?) -> Void in
// this is where I want to send the id to the array in the column of the correct post
object["passengers"] = userId
object?.saveInBackgroundWithBlock{
(success: Bool, error: NSError?)-> Void in
if (success) {
println("request deleted")
}
else {
println("cannot delete")
}}
})
The error I am getting is on the line object["passengers"] = userId
This is the error message cannot assign value type string to a value of type anyobject
答案 0 :(得分:2)
您收到错误的原因是因为object: PFObject?
仍未解包,这意味着其值可能为nil or PFObject
。
var appendToPassengerArrayQuery = PFQuery(className: "Posts")
appendToPassengerArrayQuery.getObjectInBackgroundWithId(cell.postIdLabel.text!, block: {
(object:PFObject?, error: NSError?) -> Void in
if object != nil {
object!["passengers"] = userId
object!.saveInBackgroundWithBlock{
(success: Bool, error: NSError?)-> Void in
if (success) {
println("request deleted")
}
else {
println("cannot delete")
}}
}
})