Mathieu Tozer's Dev Blog

Cocoa, the development of Words, and other software projects (including those dang assessment tasks).




Words: Merging Lookup and Words


E-mail this post



Remember me (?)



All personal information that you provide here will be governed by the Privacy Policy of Blogger.com. More...



Ok, I'm going to try and merge the two projects so that I can automatically search for word definitions when I add them.

I've just realised I can hand the management of dictionaries to core data. This way they'll persist.

This isn't turning out to be as easy as I would have liked. So there are going to have to be some minor changes to the model and the controller. I've subclassed NSArrayController to DictionariesArrayController which takes care of the UI outlets and actions, and automatically prepares CD Dictionary entities. The only action to far is 'connect' which will be invoked when the user has entered dictionary details. It will create a new entitiy with the appropriate relationship to whichever language is selected, and plop the data that must persist between launches of the application into the entity (server, database, username, password). Then it should invoke the dictProtocolDictionary's own awakeFromInsert method which will then make the actual connection. In this way, when dictionaries are loaded at launch time into the array, they can reconnect to their servers and be ready to define words.

I've got a problem: The NSArrayController seems to only want to handle objects of one type. Why is this so? Surely I should be able to string up any kind of object I like in it. addObject:object kind of situation.
Maybe it's bindings that's restricting me. The tableview needs to know what to display. But I've told the arrayController that it's got to manage entities of type Dictionary, which is an abstract class. Which means that you can't actually make of these objects, to do so is useless! It's actually the same problem I've had with trying to get smart lists and manual lists in the same view. What if the array controller managed two separate arraycontrollers, then then pulled the two together into the same array? That would be a bit messy methinks.

I possibly don't need to have core data manage the Dictionary entity as such. I mean, if I never actually have an instance of one, then why does core data need to know? Entity DictProtocolDictionary can still have a relationship with Language, so that dictionaries of that type can know to whom they belong. The subclass behaviour can come from the manual hardcoding of the entities classes. The ArrayController can directly manage dictProtocolDictionaries for now.

Here's what the connect button in the controller object should do, as far as I can see so far.
- (IBAction)connect:(id)sender
{
//create a new DictProtocolDictionary in the moc
//create a new dictionary entity and populate it's data.
//add it to the array
//(this should invoke the entity's awake from insert method which will make the actual connection)
//once you're connected and there were no errors, clear the UI, ready for the next connection

}

Actually, awakeFromInsert isn't entirely appropriate. Because it isn't called when the object is being recalled from the moc. What we need is something that will go through the dictionaries in the system and connect them when they are summoned out of the moc.
awakeFromFetch is more appropriate! (For reconnecting).

So now I am able to create and delete persisting dictProtocolDictionaries in Words proper, which associate themselves to languages. The next thing to do is to make sure they are connected not only when they are fetched by the window, but at launch time too, so that they are connected and available even when the dictionary pane hasn't been opened yet (can work around this for a while).
Each time a word is entered, the applicationController should try to find definitions for it. Words that have been defined are checked off as having been done so. This is so that later on the application can go though and find undefined words and define them.


Still more work before I can call a milestone with a screenshot ;-)


0 Responses to “Words: Merging Lookup and Words”

Leave a Reply

      Convert to boldConvert to italicConvert to link

 


+RSS | dev blog | Portfolio

About me

My status

Previous posts

  • my del.icio.us
  • my flickr