0

I'm working with the Parse SDK for my project. It first displays a list of Categories in a PFQueryTableView. On selecting a category it displays the sub categories associated to the selected category, also in a PFQueryTableView. This sub category class has a pointer value to the first Categories class.

enter image description here

In the sub category view, I have an option to add a new subcategory. What I would like to do is to add a new row to the sub categories table but have it linked to the Categories class that was just selected. i.e. link it to the pointer "Cat" in the sub categories table.

    PFObject *newWord = [PFObject objectWithClassName:@"words"];

    newWord[@"word"] = self.wordTextField.text;
    newWord[@"user"] = [PFUser currentUser];
    newWord[@"Cat"] = @"Categories";

    [newWord saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {

        } else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error!"
                                                                message:[error.userInfo objectForKey:@"error"]
                                                               delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
    }];

I keep getting this error:

[Error]: invalid type for key Cat, expected *Categories, but got string (Code: 111, Version: 1.8.0)

Anyone know what the problem is? Or how I can solve this to link to the pointer in my table?

1
  • 2
    I don't know anything about Parse (never used it), but the error message seems pretty self explanatory. Looks like you should be creating the Categories object with something like PFObject *categories = [PFObject objectWithClassName:@"Categories"];, filling it in and then assigning it to newWord[@"Cat"];. Commented Aug 20, 2015 at 12:43

1 Answer 1

1

As @trojanfoe already pointed out correctly, you are passing in a wrong object. When querying for/writing a pointer you need to pass in a pointer and not a string.

This is how it should look like in your case:

newWord[@"Cat"] = [PFObject objectWithoutDataWithClassName:@"Categories" 
                                                  objectId:@"{ID_OF_THE_CATEGORY_OBJECT}"];

Alternatively, if you already have a local instance of the category at hand at that point of your app's flow, you can set the Cat property to this object directly like this

newWord[@"Cat"] = myInstanceOfTheCategory;
Sign up to request clarification or add additional context in comments.

1 Comment

I understand now thank you. I passed the objectId from the first view controller to the view controller where I add the new word and used this, now it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.