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

  • SEARCH
  • Home
  • 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 8103769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:38:45+00:00 2026-06-05T23:38:45+00:00

I have a working project that Im amending, it crashes after trying to use

  • 0

I have a working project that Im amending,

it crashes after trying to use coredata,

The project didnt have coredata before, so it was added,

as it was for a previous base sdk [number??], applicationDocumentsDirectory returns a NSString, and not a URL,

I have changed it to work?? but is crashing when attempting to use coredata,

#import "QRGenAppDelegate.h"

//#import "QRGenViewController.h"

#import "MainViewController.h"


@implementation QRGenAppDelegate


//@synthesize window; //viewController

@synthesize window = _window;
@synthesize navigationController = _navigationController;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;

- (void)dealloc
{
    [__managedObjectModel release];
    [__managedObjectContext release];
    [__persistentStoreCoordinator release];
    [_window release];
    [_navigationController release];

    //[viewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    MainViewController *menuVC= [[[MainViewController alloc]init]autorelease];

    self.navigationController = [[UINavigationController alloc]initWithRootViewController:menuVC];

    //self.window.rootViewController = menuVC;

    self.navigationController.navigationBar.hidden = YES;

    [self.window addSubview:self.navigationController.view];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];



    return YES;
}


//CD

//Explicitly write Core Data accessors
- (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;
    }
    __managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];

    return __managedObjectModel;
}

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil) {
        return __persistentStoreCoordinator;
    }


    //mi solucto!!

    //NSURL *storeURL= [NSURL URLWithString:[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ClientOcci.sqlite"]];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"db.sqlite" ofType:nil];

    NSURL *storeURL = [NSURL URLWithString:filePath];

   // NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ClientOcci.sqlite"];
    //NSURL *storeURL = [[self applicationDocumentsDirectory]    URLByAppendingPathComponent:@"ChildCare_v02.sqlite"]; //actual SDK style for blank db

    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 - Application's Documents directory

// Returns the URL to the application's Documents directory.
+ (NSString*)applicationDocumentsDirectory {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return documentsDirectory;
}
//CD 


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

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

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

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

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



@end

it crashes in:

__managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];

EXC_BAD_ACCESS

so how I have tried in the project settings to make the base SDK 5.1 but still crashing,

why my project doesnt like the URL as return method?
how to fix it?
if I change this to a newer SDK will brake in other methods?

EDIT>>
I have tried suggestion of @ierror,

adding to my rootVC:

if (managedObjectContext == nil) { 
        managedObjectContext = [(QRGenAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
        NSLog(@"After managedObjectContext: %@",  managedObjectContext);}

But now is crashing in the appDelegate,

in

- (NSManagedObjectModel *)managedObjectModel {
    if (__managedObjectModel != nil) {
        return __managedObjectModel;
    }
    __managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain]; // crashes here!!!

    return __managedObjectModel;
}

what to do?

thanks a lot!

  • 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-06-05T23:38:47+00:00Added an answer on June 5, 2026 at 11:38 pm

    Refer to this question on stack overflow

    Core data error iPhone

    It will resolve your issue

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

Sidebar

Related Questions

I have a console project that I have been working on. I added log4net
I have a project on github that I have been working on before. However,
I have a working Android tuner project app that I want to use as
I'm working on a project that have the following need: use source ip address
Hey so I have been working on a project that I want to be
I have a django project that I have been working on as a solo
On the project that I'm currently working I have a requirement to run a
I'm working on a project that needs to have a list of weekdays. I
I'm working on a project that will have a single table holding lots and
I'm working on a project that needs to have flexible authorization. What I mean

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.