• 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
Re: Invoking add: operation to an ArrayController manually (CoreData)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Invoking add: operation to an ArrayController manually (CoreData)


  • Subject: Re: Invoking add: operation to an ArrayController manually (CoreData)
  • From: Chris Hanson <email@hidden>
  • Date: Tue, 19 Sep 2006 09:23:57 -0700

On Sep 19, 2006, at 6:07 AM, Konni Scheller wrote:

I'm working on a way to insert manually entities into a managed object context which were
usally controlled by array controllers.


How is it possible to invoke the IBActions add: / remove: eg. to an array controller manually?

Are you really sure you want to interact with your array controller directly? Or do you want to manipulate your model objects, and have the changes reflected in your user interface? Generally in Cocoa and other MVC-based frameworks, controllers are there to mediate between the graph of your model objects and any views on it. They aren't there for the graph of the model objects to use to interact with itself.


Other Question, how is it possible to insert a entity manually?

It's important to use proper terminology. Doing so makes it easier for you and others to find the information to help you. It can also help lead you to a solution a lot more easily, because if you think about the problem using the same terminology as the framework, chances are that you'll be able to come up with the names of the API you need and get them right.


An entity is a kind or type of object, similar to the way a class is. So you're not asking whether it's possible to manually insert an entity in a managed object context; you're asking whether it's possible to manually insert an *instance* of an entity -- otherwise known as a managed object -- in a managed object context. And the answer to that is yes.

One way is to instantiate your managed object directly. If you do so, you MUST be certain to invoke the designated initializer - [NSManagedObject initWithEntity:insertIntoManagedObjectContext:] (and not just -init). Pass it the managed object context you want to insert the managed object in.

Another way is to use the convenience method +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:]. This will give you back an autoreleased object of the class specified for the named entity, inserted in the given managed object context.

  -- Chris

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Invoking add: operation to an ArrayController manually (CoreData) (From: Konni Scheller <email@hidden>)

  • Prev by Date: Re: "New" validateMenuItem not being called?
  • Next by Date: Re: stepper motors + OS X
  • Previous by thread: Re: Invoking add: operation to an ArrayController manually (CoreData)
  • Next by thread: NS vs CFNotification
  • Index(es):
    • Date
    • Thread