我正在尝试更新我的 Objective-C iOS 应用程序以使用 Parse 的本地数据存储,以便我的 PFQueryTableViewController 子类可以从本地数据存储中获取 PFObjects,但我收到了一个错误。在我的应用程序委托中,我有:
[Parse enableLocalDatastore];
在我的 PFQueryTableViewController 子类中,我重写了 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);
}
}];
}
结果得到“固定好”。我的 queryForTable 方法是:
- (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;
}
当我运行它时,我得到了这个结果:
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
).
即使与 Internet 上的本地数据存储相关联,我也没有遇到此错误。当我注释掉时[query fromLocalDatastore];
,它工作正常,好像本地数据存储未启用(如果未连接到 Internet,则不会加载)。可能是什么问题呢?