• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSScriptCoercionHandler ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSScriptCoercionHandler ?


  • Subject: Re: NSScriptCoercionHandler ?
  • From: Dustin Voss <email@hidden>
  • Date: Tue, 21 Feb 2006 21:09:34 -0800

First, did you write a coercion handler and register it? Is it actually called?

According to the docs, you write a class, with a class method that does the coercion, and register the class and method with NSScriptCoercionHandler's - registerCoercer:selector:toConvertFromClass:toClass: method. NSScriptCoercionHandler's -coerceValue:toClass: method calls the method you've registered.

If everything is okay there, I have some working code I can send you.


On 21 Feb 2006, at 5:19 PM, Jim Correia wrote:

Does anyone have a working example of using NSScriptCoercionHandler?

The documentation says:

coerceValue:toClass:
Returns an object of the class toClass representing the value specified by value.


- (id)coerceValue:(id)value toClass:(Class)toClass

Discussion
Returns nil if an error occurs. The object is autoreleased, so you must retain it until you are finished with it.

Yet the following code always returns the input, without coercion or error.


	id input = nil;
	id output = nil;

input = [NSNumber numberWithInt: 3];
output = [[NSScriptCoercionHandler sharedCoercionHandler] coerceValue: input toClass: [NSString class]];
NSLog(@"coerced value = (%p, %p) %@", output, input, output);


input = [NSAppleEventDescriptor descriptorWithString: @"testing"];
output = [[NSScriptCoercionHandler sharedCoercionHandler] coerceValue: input toClass: [NSTextStorage class]];
NSLog(@"coerced value = (%p, %p) %@", output, input, output);


input = [NSAppleEventDescriptor descriptorWithString: @"Mac OS X:Users:correia:"];
output = [[NSScriptCoercionHandler sharedCoercionHandler] coerceValue: input toClass: [NSURL class]];
NSLog(@"coerced value = (%p, %p) %@", output, input, output);



2006-02-21 20:17:57.624 CoercionTest[23500] coerced value = (0x31bb30, 0x31bb30) 3
2006-02-21 20:17:57.628 CoercionTest[23500] coerced value = (0x350820, 0x350820) <NSAppleEventDescriptor: 'utxt'($00740065007300740069006E0067$)
2006-02-21 20:17:57.629 CoercionTest[23500] coerced value = (0x352da0, 0x352da0) <NSAppleEventDescriptor: 'utxt'($004D006100630020004F005300200058003A00550073006500720073003A00 63…$)


Thanks,
Jim _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: NSScriptCoercionHandler ?
      • From: Jim Correia <email@hidden>
References: 
 >NSScriptCoercionHandler ? (From: Jim Correia <email@hidden>)

  • Prev by Date: Retain Release functionality in C++ library
  • Next by Date: Re: Retain Release functionality in C++ library
  • Previous by thread: NSScriptCoercionHandler ?
  • Next by thread: Re: NSScriptCoercionHandler ?
  • Index(es):
    • Date
    • Thread