• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Binding to managedObjectContexts using dictionary hangs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Binding to managedObjectContexts using dictionary hangs


  • Subject: Binding to managedObjectContexts using dictionary hangs
  • From: "Arthur C." <email@hidden>
  • Date: Wed, 19 Nov 2008 12:35:32 +0100 (CET)

I have a Core Data application with a double Core Data implementation,
that is, there are two managedObjectModels, persistentStoreCoordinators
and managedObjectContexts.
These are referenced by the following methods:

// appDelegate.h
- (NSPersistentStoreCoordinator *)
persistentStoreCoordinatorForConfiguration: (NSString *) configuration;
- (NSManagedObjectModel *) managedObjectModelForConfiguration: (NSString
*) configuration;
- (NSManagedObjectContext *) managedObjectContextForConfiguration:
(NSString *) configuration;

- (NSManagedObjectContext *) managedObjectContextIpAddresses; // used for
bindings
- (NSManagedObjectContext *) managedObjectContextRecipes;         // used
for bindings

To make the code cleaner and generic for N objectContexts, I'd like to
have them all in an NSDictionary, and bind to the dictionary instead.

So, I'd have

- (NSMutableDictionary *) managedObjectContextDictionary;

which I fill in the appDelegate's init (to do it as early as possible) as
follows:

- (id) init
{
	self = [super init];
	if (self != nil)
	{
		managedObjectContextDictionary		= [[NSMutableDictionary alloc] init];
		persistentStoreCoordinatorDictionary	= [[NSMutableDictionary alloc] init];
		managedObjectModelDictionary		= [[NSMutableDictionary alloc] init];

		NSArray * keys   = [NSArray arrayWithObjects: recipesConfigurationKey,
ipAddressesConfigurationKey, nil];

		for(unsigned int i = 0; i < [keys count]; i++)
		{ // we do this because of the bindings
			NSString * key = [keys objectAtIndex: i];
			[managedObjectContextDictionary setObject: [self
managedObjectContextForConfiguration: key] forKey: key];
		}
	}
	return self;
}

Problem: when I use this, and bind to
managedObjectContextDictionary.recipes and
managedObjectContextDictionary.ipAddresses, the application *sometimes*
hangs after startup. That is, the interface does not work, and there is no
spinning ball either; it is just dead.
When using the debugger, it does work OK.
I checked that the whole Core Data implementation is set up, as well as
the dictionary.

Questions:

1. What could be the difference with binding to

- (NSManagedObjectContext *) managedObjectContextRecipes
{
	return [self managedObjectContextForConfiguration: recipesConfigurationKey];
} ?

2. Is it correct to set up the dictionary in - init?
3. Could there be a timing problem?


Thanks in advance,
Arthur C.






_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: NSDecimalNumber & NSString question
  • Next by Date: InputManagers in Leopard
  • Previous by thread: RE: Core data save error with multiple persistent stores [SOLVED]
  • Next by thread: InputManagers in Leopard
  • Index(es):
    • Date
    • Thread