Database Reference
In-Depth Information
Figure 42—The distributed client user interface
Opening the
MainMenu.xib
file in Interface Builder, we add a new
NSObject
to the
xib and set its class to
AppDelegate
. We then need to bind the
NSApplication
delegate
outlet to the
AppDelegate
. Next we add an
NSArrayController
to the xib and bind its
content array to the
AppDelegate
with a model key of
filteredObjects
. Lastly, we
add an
NSTableView
to the window, expanding it to take up the entire window
and assigning the first column to the
NSArrayController
with a controller key of
arrangedObjects
and the model key path set to
childCount
. The second column's
value should also be set to the
NSArrayController
with a controller key of
arrange-
dObjects
and the model key path set to
name
. Once that is complete, we can
close Interface Builder and open the
AppDelegate
.
-applicationDidFinishLaunching: Implementation
Like most application delegate objects, our custom code will start in the
-applica-
tionDidFinishLaunching:
. The first thing our client needs to do is find a server to connect
to. To accomplish this task, we initialize an
NSNetServiceBrowser
and set our
AppDelegate
as its delegate. We then configure it to search for our server using the
#define
settings in the protocol that we imported. The browser will run in the background
and start searching for servers on the local network. If it finds a server, it calls
-netServiceBrowser:didFindService:moreComing:
.
- (
void
)applicationDidFinishLaunching:(NSNotification*)notification
{
NSNetServiceBrowser *myBrowser = [[NSNetServiceBrowser alloc] init];
[myBrowser setDelegate:self];
[myBrowser searchForServicesOfType:kServiceName inDomain:kDomainName];
}