Archive for the ‘Software’ Category

Cocoa – separate window controller for the MainWindow

February 9, 2010

Imagine you have created a Cocoa Application in XCode and started to implement your stuff in the MainWindow of the application. As you do more work this class gets bigger and bigger. A possible solution is to factor out the code responsible for the MainWindo in it’s own controller class. With a separate controller for the MainWindow of the application the AppDelegate class keeps much cleaner.
For doing this an extra nib for the MainWindow has to be created and therefor an extra WindowController, e.g. MainWindowController. The AppDelegate is now responsible for the MainMenu and has no own window. Be sure to delete the window in the MainMenu.xib file if is already contained.

On applicationDidFinishingLaunching in AppDelegate the MainWindowController has to be created and called to show it’s window.

– (void)applicationDidFinishLaunching:(NSNotification*)notification
{
 // load the app’s main window
 mainWindowController = [MainWindowController alloc];
 [mainWindowController setManagedObjectContext:[self managedObjectContext]];
 [mainWindowController initWithWindowNibName:@”MainWindow”];
 [mainWindowController showWindow:self];
}

If CoreData is being used, the MainWindowController needs access to the ManagedObjectContext. In this sample I created an extra method for setting the context.

After doing this the GUI of the MainWindow can be designed in InterfaceBuilder. The FilesOwner of the MainWindow is now the MainWindowController class and the FilesOwner of the MainMenu remains AppDelegate.
Further a connection has to be made from FilesOwner to the window, to set the window outlet. And vice versa from the window to the FilesOwner to set the delegate.

For a sample on how to create an extra controller for the MainWindow see the SourceView sample from Apple. This sample does not use CoreData.

This sceanrio is a way for single document applications. If you are creating a document based application with multiple windows, there is another approach to create the initial window controllers for the document. The method makeWindowControllers from NSDocument has to be overridden.

Advertisements

Implementing an OpenSocial Container

June 25, 2009

A few days ago I have finished my thesis about implementing the opensocial api into an existing social network OpenSocialContainer.

The underlying social network is a prototype work for a german university. The document gives an introduction to opensocial and shows the work to be done for implementing the api in a social network using shindig. Besides the technical aspects like creating the appropriate iframe url, application management aspects for the social network, like installing an app are also shown.
The work closes with a discussion of opensocial. In this discussion I have also mentioned the ebay selling manager applications which sits on top of google gadgets and bring their own api. I think this is only one approach and much more for other fields will follow in future.
The work is written in German.