|
|
Sample Programs from NeXSTEP 3.3
/* DictionaryDataSource.m:
* You may freely copy, distribute, and reuse the code in this example.
* NeXT disclaims any warranty of any kind, expressed or implied, as to its
* fitness for any particular use.
*
* Written by EO Development Team
* Last modified 07/26/94 Mai Nguyen
*
* Example of a non-database data source implementation
*/
#import "DictionaryDataSource.h"
@implementation DictionaryDataSource
- init
{
return [self initWithKeys: nil];
}
- initWithKeys: (NSArray *)k;
{
[super init];
array = [[NSMutableArray alloc] init];
if (k)
keys = [[NSArray alloc] initWithArray: k];
return self;
}
- (void)dealloc
{
[array release];
[keys dealloc];
[super dealloc];
}
/* Return a set of keys describing the data bearing objects */
- (NSArray *)keys
{
return keys;
}
/* Returns a new data bearing object */
- createObject
{
id anObject = [[NSMutableDictionary alloc] init];
return anObject;
}
/* Inserts the object in the data source */
- (BOOL)insertObject:object
{
[array addObject: object];
return YES;
}
- (BOOL)canDelete
{
return YES;
}
/* Removes the object from the data source */
- (BOOL)deleteObject:object
{
[array removeObject: object];
return YES;
}
/* Saves edits to the object */
- (BOOL)updateObject:object
{
// NOOP
return YES;
}
- (NSArray *)fetchObjects
{
return array;
}
/* Saves insertions, removals and updates to storage */
- (BOOL)saveObjects
{
return YES;
}
/* Since the DictionaryDataSource does not use an eomodel, this method
* just returns the value.
* No type coercion is needed.
*/
- coerceValue: value forKey: (NSString *)key
{
return value;
}
@end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.