我试图更新我的Objective-C iOS应用程序以使用Parse的本地数据存储区,以便我的PFQueryTableViewController子类可以从本地数据存储区获取PFObject,但我收到错误。在我的应用代表中,我有:
[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
).
即使与互联网上的本地数据存储相关联,我也没有遇到此错误。当我注释掉[query fromLocalDatastore];
时,它工作正常,就像没有启用本地数据存储区一样(如果没有连接到Internet,则不会加载)。可能是什么问题?
答案 0 :(得分:0)
我今天遇到了一个非常类似的问题 - 为了使其工作,我不得不在查询中替换以下内容:
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
代表
PFQuery *query = [NameOfMyPFObjectSubclass query];