1

I've got a list of 2000+, almost the same, 'NSString' attributes I need to "import" in my .xcdatamodel-file.

If I could open the xcdatamodel-file using an XML-like-text-editor, like a .plist-file, I can add all of my attributes, but I can't find a way how.

I managed to programmaticly create the attributes (using this tutorial), but then I can't set or fetch the attribute's data.

The list should look like:

["str_1_1"],["str_1_2"],["str_1_3"],...,["str_49_4"],["str_49_5"],...

Is there a way to programmaticly add attributes / set and fetch data from attributes?

OR

Is there a way to staticly add all possible attributes without clicking the +button over 2000 times?

Joshua W
  • 111
  • 10
  • Why can't you set or fetch data after programmatically creating the managed object model? – Martin R Oct 15 '13 at 18:17
  • Maybe because of incompetence, but the error says **+entityForName: could not locate an entity named 'entityname' in this model.**. The tut mentioned earlier had me also dynamically creating the entity. – Joshua W Oct 15 '13 at 18:22

1 Answers1

2

You can just open the model file in any text editor. If you have the file compatibility for the file set to Xcode 4 or higher, it's even easy to edit.

The model Foo.xcdatamodel is actually a directory. Inside that is a file named contents, which is nicely formatted, easily readable XML. Edit that. A string attribute will look something like:

<attribute name="stringAttribute" optional="YES" attributeType="String" syncable="YES"/>

Add one or two string attributes in Xcode and then duplicate/edit them as needed.

A couple of notes:

  • Obviously, it's your job to get the syntax right. This is not documented but also not hard to figure out. If you end up with a broken model file that won't compile, you got something wrong.
  • It's probably a good idea to quit Xcode first. It might not freak out if you edit the model file while it's running, but you never know.
  • Having 2000+ string attributes is frankly terrifying and suggests an extremely bad data model. Before editing the model and adding all of these, please carefully consider whether there's a less extreme solution.
Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • Thanks Tom! I'll check this out and post the results. The 2000+ problem has something to do with every attribute being populated with an entire HTML page. There are exactly 1189 of them, in like 40 languages, so that makes 47560 HTML pages. All of the languages are optional to install, but I need to have room for all of them. Next to that, the Core Data is new to me. I usually build DB-structures on Firebird and MySQL db's, so maybe I'll think of a better solution. – Joshua W Oct 15 '13 at 18:31
  • 1
    Yeah, sorry, "show package contents". I'm used to taking the command-line approach, where it looks just like any other directory. – Tom Harrington Oct 15 '13 at 18:50
  • Weird issue: I managed to add stuff to the `contents` file, but I still get **+entityForName: could not locate an entity named 'entityname' in this model.**. Maybe I caused this myself by trying to recreate (delete > create) the .xcdatamodel-package. Any ideas? :/ – Joshua W Oct 15 '13 at 18:51
  • I'll make a new question for this, after I've done some Googling. You've answered this question, @Tom ;)... Thanks! – Joshua W Oct 15 '13 at 19:01
  • If you could take a look at [my other question](http://stackoverflow.com/questions/19389191/re-add-the-xcdatamodel-to-the-build-settings), I would greatly appreciate it :) – Joshua W Oct 15 '13 at 19:15