Mailing Lists: Apple Mailing Lists

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

-descriptorAtIndex: limitations (Re: Extract text out of NSAppleEventDescriptor)



Christopher Nebel wrote:

Incidentally, getting a particular value out of an AERecord (or an
AppleEvent, such as you have) using -descriptorAtIndex: is not
reliable, since there may be other items, and they're not guaranteed
to be in any particular order.  Use "descriptorForKeyword:'----'"
instead.


This is a weakness of the NSAppleEventDescriptor API. The C equivalent, AEGetNthDesc, returns both key and value, whereas - descriptorAtIndex: returns only the value. This makes it impossible for NSAppleEventDescriptor to unpack AERecords containing arbitrary keys; instead you have to get a pointer to the raw AEDesc and iterate over it using AEGetNthDesc. See objc-appscript's [AEMCodecs - unpackAERecord:] method for an example of how to do this [1]:

	http://appscript.svn.sourceforge.net/viewvc/*checkout*/appscript/objc-appscript/trunk/src/Appscript/codecs.m

BTW, if anyone fancies filing a feature request, the proper solution would be for NSAppleEventDescriptor to provide a -keys or - keyAndDescriptorAtIndex: method. While you're at it, you might also ask for C and ObjC APIs to iterate over an AppleEvent's attributes, since neither currently provides a way to extract event attributes without knowing all the keys in advance.

has

[1] Or, heck, just use AEMCodecs to do all your packing and unpacking for you; that's what it's there for.
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org


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

This email sent to 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.