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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:28:56+00:00 2026-05-26T13:28:56+00:00

I’m working with the new UIDocument features in iOS 5.0. I have an existing

  • 0

I’m working with the new UIDocument features in iOS 5.0. I have an existing application that uses multiple different Data Models (momd files). According to the documentation for UIManagedDocument, you can override -(NSManagedObjectModel*)managedObjectModel to load a specific Data Model (the default is load all found data models merged together). Both data models have overlapping model names with different schemas, so this is not desirable in my case.

Relevant Apple Doc

So, the problem I have here in a simple sample, is that I can override the function, but I cannot assign it’s result. It is both private, so _managedObjectModel cannot be accessed by the subclass; and, it is read-only, so self.managedObjectModel cannot be assigned..

I’ve looked for a UIManagedDocument example that does override managedObjectModel, but Apple doesn’t appear to provide one.

I may be able to define a new instance variable _myManagedObjectModel and assign that. Then return that on the accessor I’m overriding. My concern is that may break some internal implementation of the UIManagedDocument that does not use the managedObjectModel accessor in preference for _managedObjectModel (which is seen often in Apples implementations…)

Seems like a straight forward problem and I suspect I’m just missing something really simple to allow a proper override.

//
//  DTNoteDocument.m
//  document-test
//
//

#import "DTNoteDocument.h"

@implementation DTNoteDocument

NSString * const kDataManagerModelName = @"Note";

-(NSManagedObjectModel*)managedObjectModel {

    if (_managedObjectModel != nil)
        return _managedObjectModel;

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *modelPath = [bundle pathForResource:kDataManagerModelName ofType:@"momd"];
    _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]]; // compile error on this line, private variable cannot be assigned

    return _managedObjectModel;
}
@end

Header:

#import <UIKit/UIKit.h>

@interface DTNoteDocument : UIManagedDocument

@end
  • 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-26T13:28:57+00:00Added an answer on May 26, 2026 at 1:28 pm

    I solved this last week, but figured I’d update to reflect my solution. If you find something better, I would be glad to see it.

    I added a unique property to my class header for starts:

    @property (nonatomic,retain,readonly) NSManagedObjectModel *myManagedObjectModel;
    

    Then added the following to my class implementation:

    -(NSManagedObjectModel*)myManagedObjectModel {
        if (myManagedObjectModel)
            return myManagedObjectModel;
    
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *modelPath = [bundle pathForResource:kDataManagerModelName ofType:@"momd"];
        myManagedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];
    
        return myManagedObjectModel;
    }
    
    -(NSManagedObjectModel*)managedObjectModel {
        return self.myManagedObjectModel;
    }
    

    Since I can override the get property for the managedObjectModel, this works out fairly well. The UIManagedDocument initializes and works fine in my tests and implementations so far. Doing a trace shows the managedObjectModel gets called on init, so I’m assuming everything is initialized correctly from the returned result.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.