Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 942663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:18:36+00:00 2026-05-15T22:18:36+00:00

I’ve any problems for app I’m developing… I’m using Core Data and I just

  • 0

I’ve any problems for app I’m developing…
I’m using Core Data and I just write initial code…
But one of my problem is: Core Data won’t load data stored in persistent store…
This is my code!

MyWishesAppDelegate.h


#import UIKit/UIKit.h
#import CoreData/CoreData.h

@interface MyWishesAppDelegate : NSObject  {

    UIWindow *window;
 UITabBarController *tabBarController;

@private
    NSManagedObjectContext *managedObjectContext_;
    NSManagedObjectModel *managedObjectModel_;
    NSPersistentStoreCoordinator *persistentStoreCoordinator_;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (NSString *)applicationDocumentsDirectory;

@end

MyWishesAppDelegate.m


#import "MyWishesAppDelegate.h"


@implementation MyWishesAppDelegate

@synthesize window;
@synthesize tabBarController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
 [window insertSubview:tabBarController.view atIndex:0];
    [window makeKeyAndVisible];

 return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions
  (such as an incoming phone call or SMS message)
  or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application
  to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background,
  optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {

    NSError *error = nil;
    if (managedObjectContext_ != nil) {
        if ([managedObjectContext_ hasChanges] && ![managedObjectContext_ save:&error]) {

            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        } 
    }
}


#pragma mark -
#pragma mark Core Data stack


- (NSManagedObjectContext *)managedObjectContext {

    if (managedObjectContext_ != nil) {
        return managedObjectContext_;
    }

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil) {
        managedObjectContext_ = [[NSManagedObjectContext alloc] init];
        [managedObjectContext_ setPersistentStoreCoordinator:coordinator];
    }
    return managedObjectContext_;
}


- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel_ != nil) {
        return managedObjectModel_;
    }
    NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"MyWishes" ofType:@"momd"];
    NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
    managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 

    return managedObjectModel_;
}


- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator_ != nil) {
        return persistentStoreCoordinator_;
    }

    NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MyWishes.sqlite"]];

    NSError *error = nil;
    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return persistentStoreCoordinator_;
}


#pragma mark -
#pragma mark Application's Documents directory

- (NSString *)applicationDocumentsDirectory {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
}


- (void)dealloc {

    [managedObjectContext_ release];
    [managedObjectModel_ release];
    [persistentStoreCoordinator_ release];

 [tabBarController release];
    [window release];
    [super dealloc];
}


@end

WishlistViewController.h


#import UIKit/UIKit.h
#import CoreData/CoreData.h

@interface WishlistViewController : UITableViewController  {

@private
 NSFetchedResultsController *_fetchedResultsController;

}

@property (nonatomic, readonly) NSFetchedResultsController *fetchedResultsController;

-(void)add;
-(IBAction)edit;

@end

WishlistViewController.m


#import "WishlistViewController.h"
#import "MyWishesAppDelegate.h"

@implementation WishlistViewController

@synthesize fetchedResultsController = _fetchedResultsController;

#pragma mark -
#pragma mark Actions

-(void)add {
 NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
 NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
 NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];

 NSError *error;
 if (![context save:&error])
  NSLog(@"Error saving entity: %@", [error localizedDescription]);

 // TODO: instantiate detail editing controller and push onto stack
}

-(IBAction)edit {
 BOOL editing = !self.tableView.editing;
 self.navigationItem.rightBarButtonItem.enabled = !editing;
 self.navigationItem.leftBarButtonItem.title = (editing) ? (@"Done") : (@"Edit");
 [self.tableView setEditing:editing animated:YES];
}

#pragma mark -
#pragma mark View lifecycle

-(void)viewDidLoad {
 [super viewDidLoad];
 NSError *error = nil;
 if (![[self fetchedResultsController] performFetch:&error]) {
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Errore caricamento dati"
              message:[NSString stringWithFormat:@"L'errore è stato: %@", [error localizedDescription]]
                delegate:self
             cancelButtonTitle:@"Ok!"
             otherButtonTitles:nil];
  [alert show];
 }
}

-(void)viewDidAppear:(BOOL)animated {
 UIBarButtonItem *editButton = self.editButtonItem;
 [editButton setTarget:self];
 [editButton setAction:@selector(edit)];
 self.navigationItem.leftBarButtonItem = editButton;

 UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                      target:self
                      action:@selector(add)];
 self.navigationItem.rightBarButtonItem = addButton;
 [addButton release];
}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
}

- (void)dealloc {
 [_fetchedResultsController release];
    [super dealloc];
}

#pragma mark -
#pragma mark Table View Methods

-(NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView {
 NSUInteger count = [[self.fetchedResultsController sections] count];
 if (count == 0) {
  count = 1;
 }
 return count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 NSArray *sections = [self.fetchedResultsController sections];
 NSUInteger count = 0;
 if ([sections count]) {
  id  sectionInfo = [sections objectAtIndex:section];
  count = [sectionInfo numberOfObjects];
 }
 return count;
}

-(UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 static NSString *WishlistTableViewCell = @"WishlistTableViewCell";

 UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:WishlistTableViewCell];
 if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:WishlistTableViewCell] autorelease];
 }

 NSManagedObject *oneWish = [self.fetchedResultsController objectAtIndexPath:indexPath];
 cell.textLabel.text = [oneWish valueForKey:@"nome"];

 /*UIImageView *cellBg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBg.png"]];
 cell.backgroundView = cellBg;*/
 /*cell.detailTextLabel.text = [oneWish valueForKey:@"costo"];*/

 return cell;
}

-(void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 // TODO: instantiate detail editing view controller and push onto stack
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

 if (editingStyle == UITableViewCellEditingStyleDelete) {
  NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
  [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];

  NSError *error;
  if (![context save:&error]) {
   NSLog(@"Errore non risolto: %@, %@", error, [error userInfo]);
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Errore salvataggio dati"
               message:@"Impossibile salvare dopo aver cancellato un elemento"
                 delegate:self
              cancelButtonTitle:@"Ok!"
              otherButtonTitles:nil];
   [alert show];
  }
 }
}

#pragma mark -
#pragma mark Fetched Results Controller

-(NSFetchedResultsController *)fetchedResultsController {

 if (_fetchedResultsController != nil) {
  return _fetchedResultsController;
 }

 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
 MyWishesAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
 NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext;

 NSEntityDescription *entity = [NSEntityDescription entityForName:@"Wish" inManagedObjectContext:managedObjectContext];

 NSString *sectionKey = nil;
 NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"nome" ascending:YES];
 NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortByName, nil];
 [fetchRequest setSortDescriptors:sortDescriptors];
 [sortByName release];
 [sortDescriptors release];
 sectionKey = @"nome";

 [fetchRequest setEntity:entity];
 [fetchRequest setFetchBatchSize:20];

 NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                    managedObjectContext:managedObjectContext
                   sectionNameKeyPath:sectionKey
                      cacheName:@"Wish"];
 frc.delegate = self;
 _fetchedResultsController = frc;
 [fetchRequest release];

 return _fetchedResultsController;
}

-(void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
 [self.tableView beginUpdates];
}

-(void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
 [self.tableView endUpdates];
}

-(void)controller:(NSFetchedResultsController *)controller
  didChangeObject:(id)anObject
   atIndexPath:(NSIndexPath *)indexPath
 forChangeType:(NSFetchedResultsChangeType)type
  newIndexPath:(NSIndexPath *)newIndexPath {

 switch(type) {
  case NSFetchedResultsChangeInsert:
   [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
   break;
  case NSFetchedResultsChangeDelete:
   [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   break;
  case NSFetchedResultsChangeUpdate: {
   NSString *sectionKeyPath = [controller sectionNameKeyPath];
   if (sectionKeyPath == nil)
    break;
   NSManagedObject *changedObject = [controller objectAtIndexPath:indexPath];
   NSArray *keyParts = [sectionKeyPath componentsSeparatedByString:@"."];
   id currentKeyValue = [changedObject valueForKeyPath:sectionKeyPath];
   for (int i = 0; i )sectionInfo
    atIndex:(NSUInteger)sectionIndex
 forChangeType:(NSFetchedResultsChangeType)type {

 switch(type) {
  case NSFetchedResultsChangeInsert:
   if (!(sectionIndex == 0 && [self.tableView numberOfSections] == 1) && [self.tableView numberOfRowsInSection:0] == 0)
    [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
   break;
  case NSFetchedResultsChangeDelete:
   if (!(sectionIndex == 0 && [self.tableView numberOfSections] == 1) && [self.tableView numberOfRowsInSection:0] == 0)
    [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
   break;
  case NSFetchedResultsChangeMove:
   break;
  case NSFetchedResultsChangeUpdate:
   break;
  default:
   break;
 }
}

#pragma mark -
#pragma mark Alert View Delegate

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
 exit(-1);
}


@end

Anyone can help me? If there are other problems in this code, you can say it to me…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:18:37+00:00Added an answer on May 15, 2026 at 10:18 pm

    Start off by running in the debugger with a breakpoint on objc_exception_throw which will cause your app to stop just before it crashes so you can see what the offending line of code is. That will tell you what is causing the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer strip_tags() will do the job.. May 16, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer It looks to me like you have both MVC 3… May 16, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer You might want to look at the bridge servlet solution… May 16, 2026 at 3:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am currently running into a problem where an element is coming back from
i got an object with contents of html markup in it, for example: string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I've got a string that has curly quotes in it. I'd like to replace
I'm looking for suggestions for debugging... If you view this site in Firefox or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.