drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

Not leeching, but no error is thrown #155

Closed Spokane-Dude closed 10 years ago

Spokane-Dude commented 10 years ago

I have setup Ensembles according to the book and the MagicalRecord example. This is my code:

 //  determine if iCloud is configured
id token = [[NSFileManager defaultManager] ubiquityIdentityToken];
if (token == nil)
{
//        NSLog(@"iCloud is NOT available");

    //  set default NSManagedObjectContext for MagicalRecord
    [MagicalRecord   setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"saori.sqlite"];  //  enable Core    Data migration
    defaultContext = [NSManagedObjectContext MR_contextForCurrentThread]; 
}
else  {  //  no iCloud, no sync'ing

//        NSLog(@"iCloud IS available");

    //  Ensemble: load the model
    NSManagedObjectModel *model = [NSManagedObjectModel MR_newManagedObjectModelNamed:@"salonbook.momd"];
    [NSManagedObjectModel MR_setDefaultManagedObjectModel:model];

    //  setup CoreData stack
    [MagicalRecord setShouldAutoCreateManagedObjectModel:NO];
    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"saori.sqlite"];  //  enable Core Data migration

    //  setup Ensemble
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource: @"SalonBook" withExtension:@"momd"];
    NSURL *storeURL = [NSPersistentStore MR_urlForStoreName: [MagicalRecord defaultStoreName]];
    cloudFileSystem = [[CDEICloudFileSystem alloc] initWithUbiquityContainerIdentifier:@"JRSD9A598D.com.pragerphoneapps.salonbook"];
    ensemble = [[CDEPersistentStoreEnsemble alloc] initWithEnsembleIdentifier:@"SalonBook"
                                                           persistentStoreURL: storeURL
                                                        managedObjectModelURL: modelURL
                                                              cloudFileSystem: cloudFileSystem];
    ensemble.delegate = self;

    //  set default NSManagedObjectContext for MagicalRecord
    defaultContext = [NSManagedObjectContext MR_contextForCurrentThread];

    //  now leech it...
    if(!ensemble.isLeeched)  {
        [ensemble leechPersistentStoreWithCompletion: ^(NSError *error)  {
            if(error) NSLog(@"Could not leech to ensemble: %@", error);
        }];
    }
    else  {  //   merge it...
        [ensemble mergeWithCompletion:  ^(NSError *error)  {
            if(error) NSLog(@"Error during merge: %@", error);
        }];
    } 

When I look at the ensemble symbols in the Debugger, after the above code is executed, this is what I see: screen shot 2014-06-19 at 9 06 07 am

Any ideas why it's not working?

drewmccormack commented 10 years ago

Are you sure it isn't leeching? Have you set a breakpoint in the callback block? The methods are asynchronous, so setting a breakpoint at the end will not help. The Magical Record example at github is the best way to see how to set it up.

Spokane-Dude commented 10 years ago

It "leeches" every time I run the app with no changes to any of the code... if it were leeching, it would only do it once, yes?

And I have followed the MR example and believe I have set it up accordingly.

Regards, Rolf

Drew McCormack mailto:notifications@github.com June 20, 2014 at 9:17 AM

Are you sure it isn't leeching? Have you set a breakpoint in the callback block? The methods are asynchronous, so setting a breakpoint at the end will not help. The Magical Record example at github is the best way to see how to set it up.

— Reply to this email directly or view it on GitHub https://github.com/drewmccormack/ensembles/issues/155#issuecomment-46697205.

drewmccormack commented 10 years ago

Does it callback the completion block? If so, is the error non-nil?

On 20 Jun 2014, at 18:28, Spokane-Dude notifications@github.com wrote:

It "leeches" every time I run the app with no changes to any of the code... if it were leeching, it would only do it once, yes?

And I have followed the MR example and believe I have set it up accordingly.

Regards, Rolf

Drew McCormack mailto:notifications@github.com June 20, 2014 at 9:17 AM

Are you sure it isn't leeching? Have you set a breakpoint in the callback block? The methods are asynchronous, so setting a breakpoint at the end will not help. The Magical Record example at github is the best way to see how to set it up.

— Reply to this email directly or view it on GitHub https://github.com/drewmccormack/ensembles/issues/155#issuecomment-46697205.

— Reply to this email directly or view it on GitHub.

Spokane-Dude commented 10 years ago

Changed the code to: // now leech it... if(!ensemble.isLeeched) { [ensemble leechPersistentStoreWithCompletion: ^(NSError *error) { if(error) NSLog(@"Could not leech to ensemble: %@", error); else NSLog(@"leeched successfully!"); }]; } and it does NOT enter the completion block...

drewmccormack commented 10 years ago

Is the ensemble non-nil? You can use CDESetCurrentLogLevel with a setting of verbose to get detailed logging. Perhaps that will show where it is stopping.

On 20 Jun 2014, at 18:34, Spokane-Dude notifications@github.com wrote:

Changed the code to: // now leech it... if(!ensemble.isLeeched) { [ensemble leechPersistentStoreWithCompletion: ^(NSError *error) { if(error) NSLog(@"Could not leech to ensemble: %@", error); else NSLog(@"leeched successfully!"); }]; } and it does NOT enter the completion block...

— Reply to this email directly or view it on GitHub.

drewmccormack commented 10 years ago

Best way is to look at the Magical Record example at github. I think that will show you. The function is in CDEDefines.h

Eg. CDESetCurrentLoggingLevel(CDELoggingLevelVerbose);

On 20 Jun 2014, at 18:44, Spokane-Dude notifications@github.com wrote:

OK... I need help on this: how do I set CDESetCurrentLoggingLevel ? (I've looked and tried different syntax, but keep getting an error..)

— Reply to this email directly or view it on GitHub.

Spokane-Dude commented 10 years ago

I figured it out and deleted my post... too late, I guess... sorry for the lame question...

Spokane-Dude commented 10 years ago

Nothing was logged to the console... btw, I am running the latest update...

drewmccormack commented 10 years ago

If you aren’t seeing anything, I really suspect that the ensemble is nil for some reason. Have you checked that in the debugger?

On 20 Jun 2014, at 18:51, Spokane-Dude notifications@github.com wrote:

Uh... where is the log output? (I assumed NSLog; if so, nothing was logged)

— Reply to this email directly or view it on GitHub.

Spokane-Dude commented 10 years ago

No, ensemble is NOT nil (see image below) screen shot 2014-06-20 at 10 25 30 am

Spokane-Dude commented 10 years ago

I'm wondering... since I used CocoaPods to do the update, which apparently went OK, maybe I should delete ensembles and re-install using CocoaPods (no update)... is there a way to tell which version of ensemble I have in my code (ie NSLog it)?

drewmccormack commented 10 years ago

All I can suggest is breaking before the leech, and stepping through the code to isolate the problem. There are many apps using the framework, so something strange must be going on here.

On 20 Jun 2014, at 19:26, Spokane-Dude notifications@github.com wrote:

No, ensemble is NOT nil (see image below)

— Reply to this email directly or view it on GitHub.

Spokane-Dude commented 10 years ago

One last question: is it safe to just remove the Pods project in XCode to effect a clean install using CocoaPods?

drewmccormack commented 10 years ago

Ah, I don't really know. That's more a Cocoapods question. I think it would be OK, but maybe worth searching on Cocoapods.

On 20 Jun 2014, at 19:49, Spokane-Dude notifications@github.com wrote:

One last question: is it safe to just remove the Pods project in XCode to effect a clean install using CocoaPods?

— Reply to this email directly or view it on GitHub.