Start a new topic

Problem with fetching relational data

Hi, using the Event and Invitation exemple I have this code:



Model headers:



@interface Event : NSObject

@property (nonatomic, copy) NSString* entityId; //Kinvey entity _id

@property (nonatomic, copy) NSString* name;

@end



@interface Invitation : NSObject

@property (nonatomic, retain) Event* event;

@property (nonatomic, retain) NSString* objectId; //Kinvey entity _id

@end



Model implementations:



@implementation Event

- (NSDictionary *)hostToKinveyPropertyMapping {

return @{

@"entityId" : KCSEntityKeyId, //the required _id field

@"name" : @"name",

};

}

@end



@implementation Invitation

- (NSDictionary *)hostToKinveyPropertyMapping

{

return @{

@"objectId" : KCSEntityKeyId,

@"event" : @"event"

};

}



+ (NSDictionary *)kinveyPropertyToCollectionMapping {

return @{@"event" /* backend field name */ : @"Events" /* collection name for invitations */};

}

@end



The code for fetching is here:



KCSCollection *invitationCollection = [KCSCollection collectionFromString:@"Invitations" ofClass:[Invitation class]];

KCSLinkedAppdataStore *store = [KCSLinkedAppdataStore storeWithCollection:invitationCollection options:nil];



[store queryWithQuery:[KCSQuery query] withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {

if (errorOrNil == nil && objectsOrNil != nil) { //Code for success fetching }

else { //Code for error fetching }

} withProgressBlock:nil];



I always get this error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'



What am I doing wrong? If no Event is related to any of the Invitations stored on Kinvey, I don't have this error. Do I have to implement any other method for translating the KinveyRef dictionary for the original Event entity? Thanks

What does your data look like? Does it have any malformed relationships? How do you create the reference dictionaries? Also can you provide the whole stack trace?
I simply got an error before the data is really dowloaded. Here's the stack:



2013-12-12 14:59:15.477 Zepig[1962:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'

*** First throw call stack:

(

0 CoreFoundation 0x022705e4 __exceptionPreprocess + 180

1 libobjc.A.dylib 0x01ff38b6 objc_exception_throw + 44

2 CoreFoundation 0x022364c6 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 390

3 CoreFoundation 0x02264029 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 73

4 Zepig 0x0009f30e -[KCSEntityPersistence updateWithEntity:route:collection:] + 1502

5 Zepig 0x00096274 __71-[KCSObjectCache updateObject:entity:route:collection:collectionCache:]_block_invoke + 68

6 libdispatch.dylib 0x032c74b0 _dispatch_client_callout + 14

7 libdispatch.dylib 0x032b4778 _dispatch_barrier_sync_f_invoke + 58

8 libdispatch.dylib 0x032b4422 dispatch_barrier_sync_f + 89

9 libdispatch.dylib 0x032b4943 dispatch_sync + 37

10 Zepig 0x000961a1 -[KCSObjectCache updateObject:entity:route:collection:collectionCache:] + 321

11 Zepig 0x000957cc -[KCSObjectCache setObjects:forQuery:route:collection:] + 956

12 Zepig 0x0006049b -[KCSCachedStore cacheQuery:value:error:policy:] + 347

13 Zepig 0x00060917 __76-[KCSCachedStore queryNetwork:withCompletionBlock:withProgressBlock:policy:]_block_invoke + 103

14 Zepig 0x0005a48b __72-[KCSAppdataStore queryWithQuery:withCompletionBlock:withProgressBlock:]_block_invoke_2 + 43

15 Zepig 0x0005863c __51-[KCSAppdataStore makeProcessDictBlockForNewObject]_block_invoke + 1308

16 Zepig 0x0005a43b __72-[KCSAppdataStore queryWithQuery:withCompletionBlock:withProgressBlock:]_block_invoke + 251

17 Zepig 0x0001cd75 __49-[KCSAsyncConnection connectionDidFinishLoading:]_block_invoke + 885

18 Zepig 0x0001c531 -[KCSAsyncConnection runBlockInForeground:] + 161

19 Zepig 0x0001c9e0 -[KCSAsyncConnection connectionDidFinishLoading:] + 112

20 Foundation 0x01dbdb59 ___NSURLConnectionDidFinishLoading_block_invoke + 40

21 Foundation 0x01d543e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62

22 Foundation 0x01bdca6e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119

23 Foundation 0x01bdc9d6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208

24 Foundation 0x01bdc8e8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76

25 Foundation 0x01bdcc98 _NSURLConnectionDidFinishLoading + 43

26 CFNetwork 0x02709e6f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111

27 CFNetwork 0x02707bac ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104

28 CFNetwork 0x027520ef ___ZNK17CoreSchedulingSet13_performAsyncEPKcU13block_pointerFvvE_block_invoke + 25

29 CoreFoundation 0x02211d59 CFArrayApplyFunction + 57

30 CFNetwork 0x026715af _ZN19RunloopBlockContext7performEv + 139

31 CFNetwork 0x027526d2 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20

32 CFNetwork 0x026713dd _ZN17MultiplexerSource7performEv + 299

33 CFNetwork 0x026711f2 _ZN17MultiplexerSource8_performEPv + 76

34 CoreFoundation 0x021f983f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15

35 CoreFoundation 0x021f91cb __CFRunLoopDoSources0 + 235

36 CoreFoundation 0x0221629e __CFRunLoopRun + 910

37 CoreFoundation 0x02215ac3 CFRunLoopRunSpecific + 467

38 CoreFoundation 0x022158db CFRunLoopRunInMode + 123

39 GraphicsServices 0x02ceb9e2 GSEventRunModal + 192

40 GraphicsServices 0x02ceb809 GSEventRun + 104

41 UIKit 0x00d61d3b UIApplicationMain + 1225

42 Zepig 0x0000dddd main + 141

43 libdyld.dylib 0x0355970d start + 1

)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)





Does this method [KCSLinkedAppStore queryWithQuery: withCompletionBlock: withProgressBlock:] is deprecated? There is a warning saying that it is now to use other method:

KCS_DEPRECATED(KCSResourceStore deprecated -- use +[KCSFileStore downloadFileByQuery:completionBlock:progressBlock:] instead, 1.18.0);
Another information I think it is important: I already save my Invitation object on kinvey with the kinveyRef dictionary for Events collection, but something is wrong when I fetch the Invitation object and the kinveyRef dictionary with the reference for Event property inside Invitation object. I just can't translate this reference:



{"_type":"KinveyRef","_collection":"Events","_id":"52a8c78cdbac155e43eec899"}



to the Event NSObject.
I am getting the exact same error every time I try to resolve a kref as well.
Hi, this problem is a bug of kinvey ios framework. If you are having problems with that, downgrade KinveyKit to version 1.22.0.
Login or Signup to post a comment