Arrays sample (Cocoa)

NOEDITSECTION

This sample shows how to use structures and arrays to transfer complex structured data to the client.

Server Requirements

This sample requires the Arrays sample (Delphi) server.

Getting Started

Build and launch the Arrays sample server. Build and launch the sample. Correct the target URL in the text box (the server IP address or host name) to provide a valid target URL for the sample server. Click the Connect button and both master and detail table views will be filled with data. Select different rows in the master table view and see how the data will change in the detail table view.

Examine the code

The AppController class is responsible for the sample operations. Examine the -(id)init constructor to see how channel and message class instances are created:

message = [[ROBinMessage alloc] init];
channel = [[ROHTTPClientChannel alloc] init];
InitializeArraysLibrary();

See how the service proxy instance is being prepared in the -(IBAction)PerformConnect:(id)sender method in order to call remote methods:

[channel setTargetUrl:[edServerURL stringValue]];
if (service) [service dealloc];
service = [[ArraysService_Proxy alloc] initWithMessage:message channel:channel];

Notice how data is being loaded into both table views in the -(void)LoadMaster method supporting property change notifications in order to allow bindings to do their job:

[self willChangeValueForKey:@"customers"];
[self willChangeValueForKey:@"orders"];
//...
data = [[service GetTables] retain];
    
customers = [[[data aCustomers] array] retain];
[self didChangeValueForKey:@"customers"];
if ([customers count]) [customersController setSelectionIndex:0];
        
orders = [[[data aOrders] array] retain];
[self didChangeValueForKey:@"orders"];

Also pay attention to how detail data is filtered with internal table view's filtering facility in the -(void)tableViewSelectionDidChange:(NSNotification *)aNotification method:

if ([aNotification object] == customersTable)
{
    id custID = [[customersController selection] valueForKey:@"CustomerID"];
    NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF.CustomerID = %@", custID];
    [ordersController setFilterPredicate:p];
}