Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional iPhone and iPad Database Application Programming
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional iPhone and iPad Database Application Programming
This is the forum to discuss the Wrox book Professional iPhone and iPad Database Application Programming by Patrick Alessi; ISBN: 978-0-470-63617-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional iPhone and iPad Database Application Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 30th, 2011, 05:15 AM
Registered User
 
Join Date: Apr 2011
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 7 - Fatal Error when tapping Hi-Pri button

The app in chapter 7, as coded by the book and also in the downloaded code, crashes when you tap the Hi-Pri button with this console output:

FATAL ERROR: The persistent cache of section information does not match the current configuration. You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:
Reply With Quote
  #2 (permalink)  
Old April 30th, 2011, 09:41 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 7%
Activity: 7% Activity: 7% Activity: 7%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

If you add the following line the crash will be eliminated.

Code:
-(IBAction)toolbarFilterHiPri:(id)sender{
    NSLog(@"toolbarFilterHiPri");
    
    // Change the fetch request to display only high pri tasks
    // Get the fetch request from the controller and change the predicate
    NSFetchRequest* fetchRequest =  self.fetchedResultsController.fetchRequest;
    [NSFetchedResultsController deleteCacheWithName:nil];
    
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"priority == 3"];
    [fetchRequest setPredicate:predicate];
    
    NSError *error = nil;
    if (![[self fetchedResultsController] performFetch:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
    
    
    
    [taskTableView reloadData];
    
}
There are numerous discussions on stackoverflow.com concerning this issue.
Google the Console error and various links will come up.

Bob
Reply With Quote
  #3 (permalink)  
Old April 30th, 2011, 10:19 AM
Registered User
 
Join Date: Apr 2011
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks again Bob! I had figured it out by looking up deleteCacheWithName: as explained in the error, just hadn't come back here yet to post it yet. And actually, you have to add that line of code to toolbarFilterAll: as well.

Last edited by scottgardner; April 30th, 2011 at 06:46 PM.
Reply With Quote
  #4 (permalink)  
Old December 24th, 2011, 06:38 PM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default This fix is creating problems for me.

I implemented the fix as noted above, it worked once but it is generating a fatal crash for me when i try to rebuild the app, even with the same code.

The problem seems to be the "Root" cache as specified in your RootViewController if you wrote your code according to the book:

- (NSFetchedResultsController *)fetchedResultsController
{
...
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
...
}

It seems to work if I disable caching altogether by setting the Cache: parameter to NIL instead of @"Root". in
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];

but this still leaves the questions as to how to make cache functionable?
Reply With Quote
  #5 (permalink)  
Old January 7th, 2012, 04:07 PM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am having the same problem as haze1021. Implementing the solution suggested by thepianoguy workes the first time i build the application but after i rebuild the application i get the FATAL ERROR message.

I have set the cacheName to nil and the application works.

Please can someone clarify how to make cache useful?

Regards,
-Ben
Reply With Quote
  #6 (permalink)  
Old January 7th, 2012, 09:32 PM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 7%
Activity: 7% Activity: 7% Activity: 7%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

The cache must be purged when the predicate changes as is does when you switch back and forth from
Code:
-(IBAction)toolbarFilterHiPri:(id)sender
to
Code:
-(IBAction)toolbarFilterAll:(id)sender
so
Code:
[NSFetchedResultsController deleteCacheWithName:nil];
should be added to both of these filter methods before the subsequent fetch is performed.

Also, when the application goes to the background you should delete the cache. This will eliminate the crash when you restart the program.
In the TasksAppDelegate.m file add the following

Code:
-(void)applicationWillResignActive:(UIApplication *)application
{
    NSLog(@"Resigning active");
    [NSFetchedResultsController deleteCacheWithName:@"Root"];
// or [NSFetchedResultsController deleteCacheWithName:nil];
}
This should resolve your problems.
Bob
Reply With Quote
  #7 (permalink)  
Old January 8th, 2012, 06:21 AM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It did indeed Bob, thanks very much.

Regards,
-Ben
Reply With Quote
  #8 (permalink)  
Old January 8th, 2012, 11:57 AM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Again,

I still seem to be getting this caching issue after implementing your solution. However, if i add this:
Code:
[NSFetchedResultsController deleteCacheWithName:@"Root"];
to the following app delegate method:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
All seems fine.

Is this due to me using the simulator for development?

Regards,
-Ben
Reply With Quote
  #9 (permalink)  
Old January 8th, 2012, 09:11 PM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 7%
Activity: 7% Activity: 7% Activity: 7%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

Ben,
I don't actually have the book (though having responded to posts in this forum so often, I am thinking I should actually go through it!) The solution I proposed works fine with the downloaded source code. I have been unable to make it crash. Some of the issues with the project came about due to changes in the implementation of CoreData from iOS 3 to iOS 4, and also due to the introduction of multitasking and apps going to the background rather than terminating in iOS 4, since the projects were originally written in iOS 3.1.x or 3.2. I may pick up a copy of the book and do the project in iOS 5 to sort out the problem you are having. It doesn't make sense to have to delete the cache upon starting the app. That should be cleanup, not initialization.
Another thing that should be done is that the code in the applicationWillTerminate… method should be moved to the applicationDidEnterBackground… method since the applicationWillTerminate will rarely, if ever, be called. From the applicationDidFinishLauching… signature you provided it appears that you did the program in iOS 5. Without having a copy of the book I don't know whether the downloaded projects have any discrepancies with the code as presented in the text, so just creating an iOS 5 project and copying the code from the download may or may not result in something comparable to what you have. It will be a couple of days before I can get my hands on a copy of the book.

Did you make any other changes to the program?
Would you mind sending a copy of your project for me to take a look at, and maybe I can see how it differs from the download that has been working for me?
Bob
ipadhelper@me.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
fatal error C1189: #error : WINDOWS.H already included tedkurtz BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 1 December 16th, 2009 02:06 PM
FATAL ERROR. Help me please??? steviej1 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 11 February 27th, 2007 07:05 AM
Fatal Error?? dparsons ASP.NET 1.0 and 1.1 Professional 0 December 18th, 2006 12:55 PM
Chapter 8 - Reporting Fatal Errors chrlynde BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 11th, 2004 07:05 PM
fatal error!!!! Ashleek007 Beginning PHP 6 October 9th, 2004 10:25 AM



All times are GMT -4. The time now is 02:38 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.