Reputation: 157
I am having trouble translating Parse documentation into new Swift requirements. I want to update an object but I keep getting back an error that I can't assign a value of type Bool
to type AnyObject
? I know the column for "viewed" is Bool
. Here is my code.
var query = PFQuery(className:"Post")
query.getObjectInBackgroundWithId(self.threadImageIds[objectIDkey]) {
(object, error) -> Void in
if error != nil {
println(error)
} else {
object["viewed"] = true // this is where error is occuring
object!.saveInBackground()
}
}
Thanks in advance.
Upvotes: 1
Views: 3236
Reputation: 1305
It is not working because you're trying to apply the subscript to the optional and not to the object, so try unwrapping
object!["viewed"] = true
Upvotes: 0
Reputation: 157
After a lot of searching and trying to unwrap optionals the way Swift wants me to, the following worked
query.getObjectInBackgroundWithId(self.threadImageIds[objectIDkey]) {
(object, error) -> Void in
if error != nil {
println(error)
} else {
if let object = object {
object["viewed"] = true as Bool
}
object!.saveInBackground()
}
}
Upvotes: 1
Reputation: 5536
You can't store a BOOL
there, you need to use a NSNumber
of a BOOL
. Try true as NSNumber
Upvotes: 0