Its probably just me as I tend to glaze over when I see “alloc” and NSanything. Thank you for your in depth explanation : I was planning to revisit your code to try and gain a greater understanding and your post gives me a flying start.
Here, mainly for amusement, is another take on it:
set theFile to (choose file with prompt "Please choose a file:" of type {"gpx"})
parseGPX(theFile)
on parseGPX(GPXFile)
tell application "System Events"
tell XML file (GPXFile's path)'s XML element "gpx"'s XML element "trk"'s XML element "trkseg"'s XML elements
script o
property outputList : XML elements 1 thru 2's value -- Initially lists of {<ele> value, <time> value}
property gpxtpList : XML element "extensions"'s XML element "gpxtpx:TrackPointExtension"'s XML element "gpxtpx:hr"'s value -- <gpxtpx:hr> values
end script
end tell
end tell
repeat with i from 1 to (count o's outputList)
tell o's outputList's item i
set o's outputList's item i to {PlotTime:end's text 12 thru 19, Elevation:beginning, HeartRate:o's gpxtpList's item i}
end tell
end repeat
return o's outputList
end parseGPX
I have never used a Script Object in my code so to check my understanding your code first creates the script object “o” from the script class and in this case the properties are populated exactly in the same way if there were no script object. Creating them inside the script object means that they belong to “o” and as you say become quicker to access. I have not seen the use of an apostrophe before and would probably use (count elevalues of o) for reasons I can’t explain
repeat with i from 1 to (count o's eleValues)
set o's output's item i to ¬
{PlotTime:o's timeValues's item i, Elevation:o's eleValues's item i, HeartRate:o's hrValues's item i}
end repeat
That’s fine. The apostrophe form’s required in AppleScriptObjC constructions, but in straight AppleScript, you can use either apostrophes or "of"s. It’s a matter of personal preference — or a personal preference’s matter, perhaps. ![]()