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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:19:14+00:00 2026-05-25T23:19:14+00:00

Suppose I create a new project with core data. A project with a root

  • 0

Suppose I create a new project with core data. A project with a root view controller.

By default, Apple adds a self.managedObjectContext reference to this main viewController.

Now I add other classes to my project.

At some point I will have to read the objects from the core data entities and I will have to access that managedObjectContext. How do you guys obtain that context from other classes?

I know I can import the rootViewController.h on the class I want to access the context, but I am trying to do that without importing the header on multiple classes, because I want to make the classes as much independent of each other as possible and because I think this is not a good solution as it will create a mess of cross references between classes. I may be wrong.

I now I can use:

managedObjectContext = [(MyAppDelegateName *)[[UIApplication sharedApplication] delegate] managedObjectContext];

but then I will have to import MyAppDelegateName.h and the problem is the same.

Is there a better way to do that?
How do you solve that?

thanks.

  • 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-25T23:19:14+00:00Added an answer on May 25, 2026 at 11:19 pm

    Reduce dependency on CoreData by wrapping either with Repository design pattern, or with just a high level Model that handles all Core Data interactions for you. Then either have the model as a statically available class, singleton it (not recommended), or pass it through your ViewControllers.

    Edit:

    Repository Pattern – define specific repositories for each of your data objects. For example, if you have Suppliers and Products, you would have 2 repository classes, and each Repository conforms to a set interface. As a illustrative example:

    @protocol Repository{
        -(id)GetByKey:(NSInteger *)key;
        -(id)GetAll;
    
        -(id)RemoveByKey:(NSInteger *)key;
        -(id)RemoveAll;
    }
    
    @interface SupplierRepository:NSObject <Repository>
    @end
    
    @interface ProductRepository:NSObject <Repository>
    @end
    

    Your core data entities will also need to conform to some conventions, such as a surrogate key. I’ve never done this, so someone else may be able to better explain. Depending on your tolerance rating, you may decide to just instantiate repositories in your ViewControllers, or you may decide to just put it in a single Model instance anyway.

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

Sidebar

Related Questions

When creating a new project using zf create project myproject it will create a
Let us suppose we are going to start new project - application that contains
I imported ApiDemos from android-sdk folder using File/New/Project/Android Project/Create Project Existing Samples. When I
I'm attempting to create a new project in TFS 2008. The process errors out
Suppose you create a new Mac OS Command Line Application using Xcode , which
Suppose you create a generic Object variable and assign it to a specific instance.
Suppose I create a very simple socket connection, how can one programatically: Find out
Suppose I create collection like Collection<IMyType> coll; Then I have many implelentations of IMyTypem
This is about inheritance in JavaScript. Suppose I create a constructor Bird(), and another
Suppose I want to create a set of observers based on type. That is

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.