Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Result of Obj-C Code Differs from call method to Same Methods



Cocoa scripting does the work of translating AppleScript objects to Cocoa objects, like a record to a NSDictionary. The problem is that it always uses the immutable variant of said objects:

list <--> NSArray
record <--> NSDictionary

not:

list <--> NSMutableArray
record <--> NSMutableDictionary

This is primarily for performance reasons. There currently isn't an easy solution that will work around this problem. Doing the mutable work inside the Objective-C code is the only viable alternative.

Tim Bumgarner
Apple Computer


On Jul 1, 2005, at 11:25 AM, Christopher Hickman wrote:

Oh, incidentally, does someone with intimate knowledge of the inner workings
of AppleScript (*cough* Chris Nebel *cough*) know why this Objective-C code
works, but the equivalent call method calls from AppleScript *don't* work?



- (NSDictionary *)setRecord:(NSDictionary *)theRecord label: (NSString *)
theLabel toValue:(id *) theValue;
{
NSMutableDictionary mutableRecord = [NSMutableDictionary
dictionaryFromDictionary:theRecord];
[mutableRecord setObject:theValue forKey:theKey];
return [autorelease mutableRecord];
}


Using call method to call this method works:
(given myRecord, myLabel, myValue)
set myRecord to (call method "setRecord:label:toValue" of myClassWithMethod
with parameters {myRecord,myLabel,myValue})
--result: entry in myRecord with label myLabel is now equal to myValue


But using call method to duplicate the logic within the method doesn't work:
(again, given myRecord, myLabel, myValue)
set mutableRecord to (call method "dictionaryFromDictionary:" of class
"NSMutableDictionary" with parameter myRecord
call method "setObject:forKey:" of mutableRecord with parameters
{myValue,myLabel}
set myRecord to mutableRecord
--result: myRecord is unchanged


Anybody know what gives?

Topher

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list (Applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/tbumgarner %40apple.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-studio mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden
References: 
 >Result of Obj-C Code Differs from call method to Same Methods (From: "Christopher Hickman" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.