small medium large xlarge

Back to: All Forums  Core Data
Bathyjb1_pragsmall
13 Dec 2009, 15:36
Ronald Bell (12 posts)

I’m used to having code I type from a book fail when it’s supposed to work, but this is a strange experience: I’m at a point where the text says the code is supposed to fail… and it works.

I’m in the data Migration chapter. I just finished creating the v2 data model, and I’ve set it to be the current version. I now have a “Grokking_Recipes_DataModel.xcdatamodeld” and inside it is “v1.xcdatamodel” and “v2.xcdatamodel”, with the latter having a tiny green badge to indicate it’s the current one. I’ve checked to make sure my datamodel looks the same as that of the downloaded code (though everything is, unhappily, named differently).

At the bottom of p78 in the PDF (p71 in the book, but I’m going from the PDF), it says “If we were to run the application right now, we would trip the error that we discussed in Section 5.1…” And yet, when I run it, everything seems to go okay. I’ve done it three times, starting from the version from the previous chapter. I never get an error. What am I doing wrong, that my program won’t crash? :)

Bathyjb1_pragsmall
14 Dec 2009, 04:54
Ronald Bell (12 posts)

I found the solution. I did a “Clean all targets” and it worked… or rather it failed correctly.

Actually, I first crashed when the assertion (in the managedObjectModel: method) failed… NSAssert(path!=nil, @”Unable to find DataModel in main bundle”);

Turns out you have to change NSString *path = [[NSBundle mainBundle] pathForResource:@”Grokking_Recipes_DataModel” ofType:@”mom”]; in method managedObjectModel: to… NSString *path = [[NSBundle mainBundle] pathForResource:@”Grokking_Recipes_DataModel” ofType:@”momd”]; …is that in the book, and I just missed it? It’s in the source code but I don’t think it’s in the book.

Of more interest to me is something slightly off-topic: how do you know when you need to “Clean all targets”?? If I hadn’t had a book to tell me I was supposed to crash, God knows how far I’d have gone (and how many bugs I’d have happily typed in) before it all came crashing down on me.

Any advice on that point?

Bathyjb1_pragsmall
14 Dec 2009, 04:55
Ronald Bell (12 posts)

(sorry for the formatting, there. It looked better when I typed it)

;)

Avatarsmall_pragsmall
14 Dec 2009, 15:45
Marcus S. Zarra (284 posts)

Hmm, that should be in the book but I will double check for the errata. Thank you for catching that and putting a smile on my face this morning.

You must be logged in to comment