...
Warning |
---|
Note: these techniques depend on deprecated technologies. Use at your own risk. - Mike Schrag |
A CocoaEOApplication (formally, in WO 5.2, Cocoa Enterprise Objects Application, but here simply CEO) is a set of objects which allow you to use the Enterprise Objects Framework (EOF) inside Cocoa. Even though the technology is not yet supported by Apple, it had been around since NeXT was independent.
...
Code Block |
---|
- (IBAction)doit:(id)sender{
[[displayGroup displayedObjects] takeValueForKey:aValue :@"aKey"];
}
|
...
An Obj-C array:
Code Block |
---|
NSArray* anObjCArray = [NSArray arrayWithObjects:objA, objB, objC, objD, nil];
NSEnumerator* en = [anObjCArray objectEnumerator];
id o = nil;
while(o = [en nextObject]){
// here your code using o,
// which will traverse all objects in the array
}
|
...
There are many solutions to this problem. The first one (for those who knows Java and Obj-C) is to have a bridgeTool.java object in charge of allocating those arrays as neaded:
Code Block |
---|
public com.webobjects.foundation.NSArray arrayFromArray(com.apple.cocoa.foundation.NSArray cocoaArray)
{
com.webobjects.foundation.NSMutableArray woArray =
new com.webobjects.foundation.NSMutableArray();
int i;
for(i=0;i<cocoaArray.count();++i){
woArray.addObject(cocoaArray.objectAtIndex(i));
}
return woArray;
}
|
...
and then use it in a fetch specification with
Code Block |
---|
id fetchSpecification =
[[NSClassFromString(@"com.webobjects.eocontrol.EOFetchSpecification")
new] autorelease];
[fetchSpecification setEntity:@"myEntity"];
[fetchSpecification setQualifier:qualifier];
|
On the other hand, if you want to use a date in your qualifier, since NSCalendarDate is not properly translated to NSTimestamp, you have to use again the bridgeTool.java trick:
Code Block |
---|
public NSTimestamp nsTimestampFromString(String dateString){
NSTimestampFormatter formatter = new NSTimestampFormatter("%d %m %Y");
ParsePosition pp = new ParsePosition(0);
NSTimestamp myNSTimestamp = (NSTimestamp)formatter.parseObject(dateString, pp);
return myNSTimestamp;
}
|
and call this from Obj-C by
Code Block |
---|
NSCalendarDate aCalendarDate; // suppose this exists
[aCalendarDate setCalendarFormat:@"%d %m %Y"];
id nsTimestamp = [bridgeTool nsTimestampFromString:[aCalendarDate description]];
|
...
It is also possible (at least in WO 5.2.4 running on Tiger) to use
com.webobjects.eointerface.cocoa.EOCocoaUtilities as follows:
Code Block |
---|
id objPath = @"com.webobjects.eointerface.cocoa.EOCocoaUtilities";
id aDate = [NSCalendarDate date];
id nsTimestamp = [NSClassFromString(objPath) timestampForGregorianDate:aDate];
|
...