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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:54:15+00:00 2026-05-29T21:54:15+00:00

I have started creating an app which uses a core data stack at the

  • 0

I have started creating an app which uses a core data stack at the back end. It has various entities within the stack (3 specifically) each of which is accessible by a different table view controller. So, for example, I have a ‘Client’ entity which is accessible by a table view controller. Once a client is selected, a new table view controller is called which displays the records in the ‘Cars’ entity etc…

At the moment, I have followed Apple’s suggestion of passing the ‘managedObjectContext’ down the chain (so to speak) that was created in the AppDelegate. This does indeed work but it means that all of my code which accesses, adds and deletes managedObjects in the stack is integrated in all of my view controllers.

I would have thought it is cleaner (and a better implementation of MVC) to create a ‘CoreDataModel’ class which handles all the interactions with my stack and each viewcontroller can call it as necessary.

Firstly, does this seem sensible/achievable?

Secondly, in my implementation, I have kept all the core data setup code in the AppDelegate and assigned the managedObjectContext to a new instance of my CoreDataModel class. However, in my first viewcontroller I call an instance method of my CoreDataModel class called (NSMutableArray *)retrieveClientList{}. I have set up a little NSLog report when the method is called correctly but this doesnt seem to be getting invoked.

As a help, I have pasted the code from my custom class, as well as the AppDelegate and the first viewcontroller. [There is a rootviewcontroller before the first tableviewcontroller which is just a main menu which i haven’t pasted here as I don’t think it matters]

Any pointers, greatly appreciated…

This is the implementation of my custom CoreDataModel class…

@implementation CoreDataModel

@synthesize managedObjectContext;

-(NSMutableArray *)retrieveClientList {

// Create fetch request
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];

NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if(mutableFetchResults == nil) {
    // Handle the error
}

NSLog(@"Got here!");
return mutableFetchResults;

}

@end

This is the implementation of my AppDelegate…

@implementation iPTAppDelegate

@synthesize window;
@synthesize navigationController;
@synthesize managedObjectContext;

#pragma mark -
#pragma mark Application lifecycle

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

// Create new CoreDataModel object
CoreDataModel *coreDataModel = [[CoreDataModel alloc] init];

NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
    //Handle the error
}
//Pass the managed object context to the new CoreDataModel object
coreDataModel.managedObjectContext = context;


//Set the navigation controller as the window's root view controller and display
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStyleGrouped];


UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;

[window addSubview:[navigationController view]];
[window makeKeyAndVisible];

[coreDataModel release];
[rootViewController release];
[aNavigationController release];

return YES;
}

And finally, this is my first viewcontroller…

#import "ClientListViewController.h"
#import "ClientViewController.h"
#import "CoreDataModel.h"

@implementation ClientListViewController

@synthesize clientsArray;
@synthesize coreDataModel;


#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
[super viewDidLoad];

// Set the title
self.title=@"Clients";

// Add the + button
// self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editMode)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(callAddClientViewController)] autorelease];

[self populateTable];
}

-(void)populateTable {

NSLog(@"Called here");
[self setClientsArray:[coreDataModel retrieveClientList]];

}
  • 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-29T21:54:17+00:00Added an answer on May 29, 2026 at 9:54 pm

    One comment on the design, I think these things are more usually implemented as singletons (see lots of examples on here for how to create one).

    At the moment, yours is not working because you aren’t passing the core data model object to your view controller. I’d expect to see rootViewController.coreDataModel = coreDataModel in your app delegate after you create the VC.

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

Sidebar

Related Questions

I have just started building my first Flask app, which currently simply returns output
I have started creating a game, and I added a second project, it's the
I have recently started creating an iPhone application using Appcelerator's Titanium. Since the application
I have finally started messing around with creating some apps that work with RESTful
I have started using Linq to SQL in a (bit DDD like) system which
I have a rails app which requires users to verify that they own a
I've been working on a web app lately, and Activerecord has started creeping me
I have a web app, that also has an iPhone and Android app using
I have started to code a web app for small businesses, and I have
In the app that io am creating, i have a custom copy of UISplitView

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.