0

既存のCoreDataSQLiteDBからデータを選択してPOSTする例を見つけることができませんでした。私のコアデータは、デバッグ出力に従って正常に構成されているようです。SQLite操作を表示するように設定しました。ブール属性で述語を実行するか、すべてをロードしようとすると、エラーは発生しませんが、オブジェクトはゼロになります。

@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];
4

1 に答える 1

0

以下を追加して動作させました:

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Offering" inManagedObjectContext:__managedObjectContext];
[request setEntity:entity];

NSError *anyError = nil;
NSArray *fetched = [__managedObjectContext executeFetchRequest:request error: &anyError];
if (fetched == nil) {
     NSLog(@"Error with fetch");
}
NSLog(@"We fetched %d objects", [fetched count]);
于 2012-07-17T15:02:34.597 に答える