views:

63

answers:

1

Hi everybody, I am a novice in Objective-C; and I could not find any solution in my Books or internet.

My question: What are the most efficient and fastest ways to use already compiled .mom and SQLite db without having the source codes?

Details: I am trying to connect my small app to the database of another application and use (read-inly) the part of its data. But the task is difficult since that app does not have SDK.

That app has a compiled .mom file and an SQLite database.

I succeeded to programmatically (not using IB) connect to the db using .mom and could manage to get the entities, fill data into the objects re-created by me etc. But I am doing every step with guesses, trials and errors. Thus the development takes a lot of time and is error-prone. The most difficult task to dissect is to-many relationships via intermediate tables.

For example: entity "Books" has a relationship to "Authors". Since the sequence of authors matters, there is an intermediate table "authorsNumbered" which contains fields: number, author, book; and the field "number" determines the exact order of authors as they should appear everywhere (important!)

I finally managed to create an ordered array of authors using NSSortDescriptor but it took me whole week to find and guess how to do it!

Would you suggest more efficient ways to deal with compiled .mom rather than the one used by me?

Thanks

A: 

If you copy the .mom file and change the extension to .plist you will get a plain text, human readable plist file which you can puzzle out with relative ease.

TechZen
wow, thanks...The .xcdatamodel file is a folder with .plist files; but I did not suspect that so-called "compiled" .mom file would be also the same. I thought it was some sort of binary...Although the format of both files is hard to dissect and map to entities. I found it more convenient to add that .mom file to my managed object context and then enumerate entities, attributes and relationships, something like this:
Proteos
//... Code for connecting to managedObjectContext... // int i; //For enumerating entities NSEntityDescription *entity=[entities objectAtIndex:i]; NSDictionary *attrs=[entity attributesByName]; //Nice way of enumerating ATTRIBUTES for (NSString *key in attrs){ NSAttributeDescription *myAttr=[attrs objectForKey:key]; NSLog(@"=>Attr:%@",[myAttr name]); }
Proteos
//Nice way of enumerating RELATIONSHIPS NSDictionary *rels=[entity relationshipsByName]; for (NSString *key in rels){ NSAttributeDescription *myRel=[rels objectForKey:key]; NSLog(@"=>Rel:%@",[myRel name]); }
Proteos
And if you feed NSLog with only myAttr and myRel (i.e. without "name" message), it will print much more info e.g. variable type etc.Well, I have already found out the structure of the model and created several classes that use two of those entities; but I am not sure how will I show this everything in GUI and how will I keep them in sync.Maybe I should have used NSArrayController which would automatically do this everything?
Proteos
You probably want to open another question about that last question. It covers a lot ground.
TechZen