Re: Coercion of list to record
Re: Coercion of list to record
- Subject: Re: Coercion of list to record
- From: Jason Bruce <email@hidden>
- Date: Thu, 7 Feb 2008 13:49:12 -0800 (PST)
People on the Cocoa list always say "don't fight the
Cocoa frameworks." I think the same thing applies
here. Rather than fighting AppleScript, why not just
use it to build a list of your own key, value
records. If the list isn't going to be very large, it
shouldn't be a problem, and if the list is large, then
a database of some sort is probably a better solution.
To build your own key, value pair:
property myRecords : {}
to makeRecord(aKey, aValue)
set newRecord to {myKey:aKey, myValue:aValue}
set end of myRecords to newRecord
end makeRecord
makeRecord("First Name","John")
to get a value based on a key,
to retrieveValue(aKey)
repeat with loopvariable from 1 to count items of
myRecords
if myKey of item loopvariable of myRecords is aKey
then
return myValue of item loopvariable of myRecords
end if
end repeat
end retrieveValue
retrieveValue("First Name")
--"John Smith"
This should work fine for a list of records of a few
hundred in number, and for longer lists Database
events.
Jason Bruce
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden