• 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: Name of data model file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Name of data model file


  • Subject: Re: Name of data model file
  • From: Matthew Firlik <email@hidden>
  • Date: Sat, 6 Aug 2005 17:40:10 -0700


On Aug 6, 2005, at 9:58 AM, mmalcolm crawford wrote:


On Aug 6, 2005, at 7:21 AM, Frédéric Testuz wrote:

I'm curious about the name of the data model file. In the documentation I only find reference to it that say to "choose an appropriate file name". So the name can be anything I want ? In the template, if I change MyDocument.xcdatamodel to ThisIsTheDocDataModel.xcdatamodel, it will not cause any problems ?

What happens if you try it?

See also <http://developer.apple.com/documentation/Cocoa/Reference/ ApplicationKit/ObjC_classic/Classes/NSPersistentDocument.html#// apple_ref/doc/uid/TP30001179-CJBJBIHA>.


The "name" of a model, as represented by the filename used to store it on disk, is really only to unique said file. One the model is loaded by Core Data, the "name" is meaningless and has no use. As Malcolm points out via the documentation, Core Data has two mechanisms to load a model:

- from a specific collection of bundles (the class method mergedModelFromBundles:)
- from a specific URL (the instance method initWithContentsOfURL:)


Most of the sample code and project templates make use of the former, and it is likely the latter goes oft unnoticed, but each has benefits. The former is useful in cases where segregation of models isn't important: for example, you may know your application and a framework it links both have models you need/want to load. Using the class method allows you to load all of the models at once without having to "think" of what the names are, or put in specialized initialization code to ensure all of your models are found.

However, in cases where may have more than one model -- and specifically in cases where the models represent different versions of the same schema -- knowing which model to load is absolutely important. Because Core Data "merges" all of the models together at runtime into a single collection, attempting to load models with the same entities would cause collisions and errors. Additionally, it may be the case where you want to store the model outside of the bundle for your application, thus requiring the need to reference it via a file-system URL.

(Note there is also a class method, modelByMergingModels:, which will merge the array of passed-in models much like the mergedModelFromBundles: method does. Thus, you can still load individual models via URLs and then unify them before instantiating a coordinator with them.)

So, you can name the model whatever you like, as long as you change it everywhere you might have typed in that specific string.

- matthew _______________________________________________
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


  • Follow-Ups:
    • Re: Name of data model file
      • From: Frédéric Testuz <email@hidden>
References: 
 >Name of data model file (From: Frédéric Testuz <email@hidden>)
 >Re: Name of data model file (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: Save authentication to keychain
  • Next by Date: Spell checking
  • Previous by thread: Re: Name of data model file
  • Next by thread: Re: Name of data model file
  • Index(es):
    • Date
    • Thread