0

I'm attempting to fetch a query from "Parse.com's cloudcode" which returns a dictionary. The dictionary contains two keys, "groups" and "invites", both being arrays.

When one of they key's is an empty array, the following error occurs:

2014-05-23 17:14:03.967 XXX[2267:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]' * First throw call stack: (0x2d589f0b 0x37d20ce7 0x2d4c7cff 0x2d4c7ac3 0x1acd5b 0x1acfef 0xddb95 0xdda07 0xedd4d 0x2fdd3d23 0x2fe83057 0x2fdd3d23 0x2fe38e7f 0x2fe38e09 0x2fdb1b73 0x2d555039 0x2d5529c7 0x2d552d13 0x2d4bd769 0x2d4bd54b 0x3242a6d3 0x2fe1c891 0xe3805 0x3821eab7) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Here's the cloud code function:

Parse.Cloud.define("GroupsAndInvites",function(request,response){
        var user = request.user;
        //query memberships and invites for the current user
        var membershipQuery = new Parse.Query("Membership").include("group").equalTo("user",user);
        var inviteQuery = new Parse.Query("Invite").include("from").include("group").equalTo("to",user);

        //make promises
        var membershipPromise = membershipQuery.find();
        var invitePromise = inviteQuery.find();

        //call when both queries are done
        Parse.Promise.when(membershipPromise,invitePromise).then(function(memberships,invites){
                //make an array of groups instead of memberships
                var groups = [];
                for(var i=0;i<memberships.length;i++){
                        groups.push(memberships[i].get("group"));
                }
                //return groups and invites
                response.success({
                        "groups":groups,
                        "invites":invites
                });
        });
});

And here's my implementation of that function on the front end:

  [PFCloud callFunctionInBackground:@"GroupsAndInvites" withParameters:nil block:^(NSDictionary *dict, NSError *error) {
    if (!error) {
      NSMutableArray *groupsArray = [NSMutableArray array];
      NSMutableArray *invitesArray = [NSMutableArray array];

      for (BVYGroup *group in dict[@"groups"]) {
        [groupsArray addObject:group];
      }

      for (BVYInvite *invite in dict[@"invites"]) {
        [invitesArray addObject:invite];
      }

      if ([strongDelegate respondsToSelector:@selector(groupStream:didFetchGroups:andInvites:)]) {
        [strongDelegate groupStream:self didFetchGroups:groupsArray andInvites:invitesArray];
      }
    } else {
      if ([strongDelegate respondsToSelector:@selector(groupStream:didFailToFetchGroupsWithError:)]) {
        [strongDelegate groupStream:self didFailToFetchGroupsWithError:error];
      }
    }
  }];

The error occurs right when a response is retrieved. It does not reach the if statement that checks for an error.

Any insight to why this might be occurring?
Thank you in advance.

1 Answer 1

2

You can not insert nil into Objective-C collections. If you need to represent a nil value in an Objective-C collection, use [NSNull null] instead.

Sign up to request clarification or add additional context in comments.

Comments

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.