Reputation: 70
let user = PFUser.currentUser()
let relation = user!.objectForKey("friendsRelation")
relation!.query().findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if let error = error {
print("Error")
} else {
print("Users Retrieved")
}
}
I'm Learning iOS development, and this parse code is not working, as I want to get Objects from current user relations. The error it's showing is
Thread 1: EXC_BAD_INSTRUCTION
Upvotes: 0
Views: 152
Reputation: 6522
Here is a much safer version that you can try:
if let user = PFUser.currentUser() {
if let relation = user.relationForKey("friendsRelation") {
relation.query().findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if let error = error {
print("Error")
} else {
print("Users Retrieved")
}
}
}else{
print("Failed to fetch relation")
}
}else {
print("Failed to get user object")
}
You can now debug and see if you fail to have the user object or the relation, if you can get both, then there might be some other issue. Also note as @danh pointed out you should be using relationForKey instead of objectForKey.
Upvotes: 1