0

I have a method that generates a PFObject and stores it in an NSMutableArray. Then a tableview populates itself with this array. However, the method that stores the PFObject is not successfully adding the object. Here is the method:

- (void)addListing{
    PFObject* userListing = [PFObject objectWithClassName:@"userListing"];
    [userListing setObject:[NSString stringWithFormat:@"John Smith"] forKey:@"userName"];
    [userListing setObject:[NSString stringWithFormat:@"408 521 3322"] forKey:@"userPhoneNumber"];
    [userListing setObject:[NSString stringWithFormat:@"Lorem Ipsum Dolor Sit Amet"] forKey:@"listingName"];
    [userListing setObject:[NSString stringWithFormat:@"$10"] forKey:@"listingPrice"];

    [listings addObject:userListing]; 
    [userListing saveInBackground];

    NSLog(@"%i", listings.count);
}

On that last line, I have the console print the amount of objects that are stored in listings but it repeatedly prints zero. Where am I going wrong?

3
  • 1
    Are you certain that listings is non-nil when this method is called? nil would also respond with 0 for a count method call. Commented Jul 29, 2013 at 0:15
  • Yep, almost certainly you never created the array for listings. Commented Jul 29, 2013 at 0:28
  • Understand that setObject on a nil pointer will quietly no-op, and count will return zero. Commented Jul 29, 2013 at 0:29

1 Answer 1

3

Make sure you are initializing the array.

listings = [[NSMutableArray alloc] init];
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.