2

I'm trying to update my Objective-C iOS app to use Parse's Local Datastore so that my PFQueryTableViewController subclass can get PFObjects from the local datastore, but I'm getting an error. In my app delegate, I have:

[Parse enableLocalDatastore];

In my PFQueryTableViewController subclass, I override objectsDidLoad:

- (void)objectsDidLoad:(NSError *)error {
    [super objectsDidLoad:error];
    [PFObject pinAllInBackground:self.objects block:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"Pinned OK");
        }else{
            NSLog(@"Erro: %@", error.localizedDescription);
        }
    }];
}

and get "Pinned OK" as a result. My queryForTable method is:

- (PFQuery *)queryForTable {
    if (![PFUser currentUser]) {
        return nil;
    }

    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    [query fromLocalDatastore];
    [query orderByAscending:@"name"];
    [query whereKey:@"user" equalTo:[PFUser currentUser]];

    return query;
}

When I run this, I get this result:

2015-03-21 17:07:21.193 Yoyo[6079:11678859] [Error]: Caught "NSInvalidArgumentException" with reason "*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]":
(
    0   CoreFoundation                      0x0000000105deaa75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000105a83bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000105cb0c78 -[__NSPlaceholderArray initWithObjects:count:] + 360
    3   CoreFoundation                      0x0000000105d0fbe4 +[NSArray arrayWithObjects:count:] + 52
    4   Yoyo                                0x00000001040b15c8 -[PFOfflineStore findAsyncForQuery:user:pin:isCount:database:] + 741
    5   Yoyo                                0x00000001040b10b0 __53-[PFOfflineStore findAsyncForQuery:user:pin:isCount:]_block_invoke + 89
    6   Yoyo                                0x000000010409ddc0 __41-[BFTask continueWithExecutor:withBlock:]_block_invoke_2 + 30
    7   Yoyo                                0x000000010409ea67 __29+[BFExecutor defaultExecutor]_block_invoke_2 + 331
    8   Yoyo                                0x000000010409eec9 -[BFExecutor execute:] + 65
    9   Yoyo                                0x000000010409dd7e __41-[BFTask continueWithExecutor:withBlock:]_block_invoke + 127
    10  Yoyo                                0x000000010409da29 -[BFTask runContinuations] + 399
    11  Yoyo                                0x000000010409d2dc -[BFTask trySetResult:] + 151
    12  Yoyo                                0x000000010409d217 -[BFTask setResult:] + 17
    13  Yoyo                                0x000000010409bf8c -[BFTaskCompletionSource setResult:] + 79
    14  Yoyo                                0x000000010409de7d __41-[BFTask continueWithExecutor:withBlock:]_block_invoke_2 + 219
    15  Yoyo                                0x000000010409ea67 __29+[BFExecutor defaultExecutor]_block_invoke_2 + 331
    16  Yoyo                                0x000000010409eec9 -[BFExecutor execute:] + 65
    17  Yoyo                                0x000000010409dd7e __41-[BFTask continueWithExecutor:withBlock:]_block_invoke + 127
    18  Yoyo                                0x000000010409da29 -[BFTask runContinuations] + 399
    19  Yoyo                                0x000000010409d2dc -[BFTask trySetResult:] + 151
    20  Yoyo                                0x000000010409d217 -[BFTask setResult:] + 17
    21  Yoyo                                0x000000010409bf8c -[BFTaskCompletionSource setResult:] + 79
    22  Yoyo                                0x000000010409e006 __41-[BFTask continueWithExecutor:withBlock:]_block_invoke_3 + 285
    23  Yoyo                                0x000000010409ddc0 __41-[BFTask continueWithExecutor:withBlock:]_block_invoke_2 + 30
    24  Yoyo                                0x000000010409ea67 __29+[BFExecutor defaultExecutor]_block_invoke_2 + 331
    25  Yoyo                                0x000000010409eec9 -[BFExecutor execute:] + 65
    26  Yoyo                                0x000000010409dd7e __41-[BFTask continueWithExecutor:withBlock:]_block_invoke + 127
    27  Yoyo                                0x000000010409dc12 -[BFTask continueWithExecutor:withBlock:] + 277
    28  Yoyo                                0x000000010409e19a -[BFTask continueWithBlock:] + 87
    29  Yoyo                                0x000000010409de48 __41-[BFTask continueWithExecutor:withBlock:]_block_invoke_2 + 166
    30  libdispatch.dylib                   0x00000001080db186 _dispatch_call_block_and_release + 12
    31  libdispatch.dylib                   0x00000001080fa614 _dispatch_client_callout + 8
    32  libdispatch.dylib                   0x00000001080e4552 _dispatch_root_queue_drain + 1768
    33  libdispatch.dylib                   0x00000001080e5b17 _dispatch_worker_thread3 + 111
    34  libsystem_pthread.dylib             0x000000010847f637 _pthread_wqthread + 729
    35  libsystem_pthread.dylib             0x000000010847d40d start_wqthread + 13
).

I haven't come across this this error even being associated with local datastore on the Internet. When I comment out [query fromLocalDatastore];, it works fine and as if local datastore isn't enabled (nothing loads if not connected to the Internet). What could be the problem?

Eugene
  • 3,417
  • 5
  • 25
  • 49
  • does the answer here help: http://stackoverflow.com/questions/27435626/pfquery-pinallinbackgroundblock-never-completes – Louis Tur Mar 22 '15 at 01:19
  • I don't think that helps me. My problem is not with pinning the objects to the local datastore after they've been queried, it is having the ability to query from the local datastore if they're in it, and if there's no Internet connectivity, by using `[query fromLocalDatastore]`. – Eugene Mar 22 '15 at 03:15

1 Answers1

0

I had a very similar issue today - To get this to work, I had to replace the following in the query:

PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

for

PFQuery *query = [NameOfMyPFObjectSubclass query];
Andrew
  • 1,038
  • 11
  • 14
  • I don't quite understand. Using that directly results in an undeclared identifier network. Are you implying that I should subclass PFObject for objects of the parse class I want, and call query on that? – Eugene Apr 17 '15 at 03:45
  • I was subclassing PFObject. So in the case of subclassing PFObject - I had to do the above instead of saying `PFQuery *query = [PFQuery queryWithClassName:@"someString"];` Regarding the problem being specific to localdatastore - are you using PFFile anywhere? – Andrew Apr 17 '15 at 18:51
  • Yes, I'm using PFFiles for each object. – Eugene May 17 '15 at 03:09