• 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
NSScriptCoercionHandler ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSScriptCoercionHandler ?


  • Subject: NSScriptCoercionHandler ?
  • From: Jim Correia <email@hidden>
  • Date: Tue, 21 Feb 2006 20:19:57 -0500

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'($004D006100630020004F005300200058003A00550073006500720073003A0063 …$)


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


  • Follow-Ups:
    • Re: NSScriptCoercionHandler ?
      • From: Dustin Voss <email@hidden>
  • Prev by Date: CFPrefDockItems sample code. Where did it go?
  • Next by Date: Re: Round Rect FLAT on Intel
  • Previous by thread: Re: CFPrefDockItems sample code. Where did it go?
  • Next by thread: Re: NSScriptCoercionHandler ?
  • Index(es):
    • Date
    • Thread