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



That sucks.

So you can assign the objects returned from Cocoa methods to AppleScript
variables and they will be that same Cocoa object, unless it a mutable
version of a toll-free bridged object?  Then you get an immutable copy of
it?

I expected that my call to NSMutableDictionary's factory method would return
an NSMutableDictionary, and that the AppleScript variable to which I
assigned that return value wouldn't be hijacked by the toll-free bridge and
replaced with an immutable copy. :(

What other classes get hijacked by the bridge?  Just NSMutableArray?
NSMutableString, too?

Well, at least I'm not crazy.  Not much, anyway.

Hey, if I subclassed NSMutableDictionary, would AppleScript turn the object
returned by a call to my factory methods into an immutable NSDictionary?  Or
is this just a "feature" of the direct subclasses of the immutables?

Topher

-----Original Message-----
From: Tim Bumgarner [mailto:email@hidden] 
Sent: Friday, July 01, 2005 11:32 AM
To: Christopher Hickman
Cc: 'AppleScriptStudio MailingList'
Subject: 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: 
 >Re: Result of Obj-C Code Differs from call method to Same Methods (From: Tim Bumgarner <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.