Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting Core Data entity attributes with User Info entries

We're looking for a way to document Core Data entities. So far the only real options I've come up with are:

  1. Document externally using UML or some other standard
  2. Create NSManagedObject subclasses for every entity and use code comments
  3. Use the User Info dictionary to create a key value pair that holds a string comment

Option 1 feels like too much extra work and something that will almost certainly be out of date 99% of the time.

Option 2 feels natural and more correct than option 1. The biggest con here is that those comments could potentially be lost if this model class is regenerated using Xcode.

Option 3 feels a little less correct than option 2, but has the added advantage of adding automation possibilities with regards to meta data extraction. For instance, in one of our apps we need to keep a real close eye on what we're storing locally on the device as well as syncing to iCloud. Using the user info dictionary it's pretty easy to automate the creation of some form of artefact which can be checked both internally and externally (by the client) for compliance

So my question is whether it would be inappropriate to use the user info dictionary for this purpose? And are there any other options I'm missing?

like image 441
nduplessis Avatar asked Mar 05 '12 10:03

nduplessis


People also ask

What is attribute in Core Data?

You can think of attributes as the columns of a table in a database. Attributes store the values of a Core Data record. There are several types of attributes, such as String, Date, Integer, Float, and Boolean.

What is codegen in Core Data?

The Codegen value is short for “code generation” – when you pressed Cmd+B to build your project, Xcode converted the Commit Core Data entity into a Commit Swift class. You can't see it in the project – it's dynamically generated when the Swift code is being built – but it's there for you to use, as you just saw.

How do I use Core Data?

Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.


1 Answers

Option 2 is what I use every time. If you look at your core data model (something.xcdatamodeld or something.xcdatamodel) you will see something like the picture below.

core data entity in XCode

You can tie your entity to whatever class you want and then put the comments in there. It helps if you keep your entity name the same as your class name to make it obvious what you've done.

Additionally this also gives you the ability to add automation. You can do this by creating custom getters and setters (accessor methods) and a custom description method.

like image 88
Jeff Wolski Avatar answered Oct 18 '22 13:10

Jeff Wolski