HI - I have been beating myself against a wall for two days to get this work and I can't seem to make it happen. After executing the array is nil. Here is the code:
Hey Steve, sorry you're having trouble! Were you able to successfully fetch data using the sample apps? I'm just trying to rule out any connection issues.
S
Steve Trombley
said
about 7 years ago
Yup - made the connection, successfully pinged.
M
Mike
said
about 7 years ago
Steve,
you need to to call the load data after the user completion block is called.
Steve Trombley
```- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"got to initalizing");
(void) [[KCSClient sharedClient] initializeKinveyServiceForAppKey:@"kid_Te1Hk6PJCO"
withAppSecret:@"9ae9c09ee3b240ed9e2f944c97c45c8e"
usingOptions:nil];
if ([KCSUser activeUser] == nil) {
[KCSUser createAutogeneratedUser:^(KCSUser *user, NSError *errorOrNil, KCSUserActionResult result){
NSLog(@"Created User");
}];
} else {
NSLog(@"User was set");
}
[KCSPing pingKinveyWithBlock:^(KCSPingResult *result) {
if (result.pingWasSuccessful == YES){
NSLog(@"Kinvey Ping Success");
} else {
NSLog(@"Kinvey Ping Failed");
}
}];
[self loadData];
}
-(id)loadData {
NSLog(@"fifniashed ping");
// KCSCollection *membersCollection = [KCSCollection collectionFromString:@"usHouse" ofClass:[memberItem class]];
KCSAppdataStore *store = [KCSAppdataStore storeWithOptions:@{ KCSStoreKeyCollectionName : @"usHouse",
KCSStoreKeyCollectionTemplateClass : [memberItem class]}];
[store queryWithQuery:[KCSQuery query] withCompletionBlock:^(NSArray *objectsOrNIl, NSError *errorOrNil) {
if (errorOrNil != nil) {
//An error happened, just log for now
NSLog(@"An error occurred on fetch: %@", errorOrNil);
} else {
//got all events back from server -- update table view
objects=objectsOrNIl;
}
} withProgressBlock:nil];
return objects;
}```
Here is the class definition and key mapping:
```import
import
@interface memberItem : NSObject
@property (nonatomic, copy) NSString *objectId;
@property (nonatomic, copy) NSString *memberFullName;
@property (nonatomic, copy) NSString *memberFirstName;
@property (nonatomic, copy) NSString *memberLastName;
@property (nonatomic, copy) NSString *memberParty;
@property (nonatomic, copy) NSString *memberDistrict;
@property (nonatomic, copy) NSString *memberState;
import "memberItem.h"
import
@implementation memberItem
- (NSDictionary *)hostToKinveyPropertyMapping
{
return @{ @"objectId" : KCSEntityKeyId, @"memberFullName" : @"FullName",
@"memberFirstName" : @"First",
@"memberLastName" : @"Last",
@"memberParty" : @"Party",
@"memberDistrict" : @"District",
@"memberState" : @"State"};
}
@end```
I am sure I am overlooking something completely obvious but I can't get it to work. Any help would be appreciated.
All the best.