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 8375289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:08:13+00:00 2026-06-09T15:08:13+00:00

__managedObjectModel is nil even modelURL exists. There is a similar post , but the

  • 0

__managedObjectModel is nil even modelURL exists. There is a similar post, but the accepted answer (rename model file and relaunch Xcode) doesn’t work for me.

- (NSManagedObjectModel *)managedObjectModel
{
    if (__managedObjectModel != nil) {
        return __managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Failed" withExtension:@"momd"];

    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

    return __managedObjectModel;
}

I po modelURL in console

(lldb) po modelURL
(NSURL *) $4 = 0x088832f0 file://localhost/Users/philip/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/9E59167C-8D9E-4ADE-BBD7-0BE9A33A6A86/Failed.app/Failed.momd/
  • 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-09T15:08:15+00:00Added an answer on June 9, 2026 at 3:08 pm

    I solved the problem after 3 hours..finally. The solution is simple though: just use the following code

    __managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
    

    instead of

    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Failed" withExtension:@"momd"];
    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    

    The reason is that I once created new model file (.xcodemodeld) and delete the old one. And the two model files have different names. In fact, the old model file is NOT deleted at all. It’s still inside the app main bundle.

    I check the iphone simulator directory and surprisingly see two compiled model files (.momd) are both there! I tried to delete the old momd. But every time my app gets running, the old momd appears again. I go check target build phase and make sure the old model file isn’t in compile sources. So weird..

    Since multiple compiled model files exist in main bundle, they need to be merged. That’s why mergedModelFromBundles: comes into play instead of a single modelURL.

    If you never delete any model file, use single modelURL should be no problem.

    Although problem solved, I don’t understand why simulator keeps all deleted model files in the main bundle. It doesn’t make sense to me. Anyone would explain?

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

Sidebar

Related Questions

I did some changes to my model (but I don't want migration yet, so
I have seen this question posted here, but always, the answer is that the
I know there are a million of these questions in SO, but this is
i've read all possible blogs and SO post on the subject - but still
Since I embeded fetch request in my model.xcdatamodeld, I need an instance of NSManagedObjectModel
Ok, I may be in well over my head here, but suspect I am
I have a coreData datamodel file which was running perfectly. Due to some special
I'm using Core Data and my app works perfectly in the simulator but on
I created an iOS project and a managed object model ( Model.xcdatamodeld ) with
I'm using Core data in an iOS project. I have the data model setup

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.