Re: NSScriptCoercionHandler ?
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