I haven’t been able to find examples of selecting data from an existing Core Data SQLite DB and POSTing it. My Core Data seems configured ok according to the debug output. I have set it display SQLite operations. When I try to do either a predicate on a Boolean attribute or a load all it doesn’t give be an error but it retrieves zero objects.
@interface Offering : NSManagedObject
@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * uploadToServerRequired;
#import "AppDelegate.h"
#import <RestKit/RestKit.h>
#import "Offering.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
RKObjectManager* manager =
[RKObjectManager objectManagerWithBaseURL: [[NSURL alloc] initWithString:@"http://localhost:8080/anywhereAboutWebServices"] ];
manager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"AnywhereAbout2.sqlite"];
NSError *error;
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"AnywhereAbout2.sqlite"];
NSURL *url = [NSURL fileURLWithPath:path];
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil] error:&error]);
else {
__managedObjectContext = [[NSManagedObjectContext alloc] init];
[__managedObjectContext setPersistentStoreCoordinator: persistentStoreCoordinator];
}
NSArray* objects = [Offering allObjects];
NSLog(@"We loaded %d objects", [objects count]);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"uploadToServerRequired == %@", [NSNumber numberWithBool: (BOOL)1]];
int count = [filtered count];
added following and got it to work: