NSURL form question

So I’m late to the game and reading @ShaneStanley’s book and @alldritt’s posts, amongst other posts here and I am trying to understand why NSURL is quoted and explicitly called by current application's class, when passing a URL to NSJSONSerialization, e.g.,…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set TheURLStr to "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=demo"

set JSONData to getUrlSource(TheURLStr)
property NSJSONSerialization : a reference to current application's NSJSONSerialization
property NSData : a reference to current application's NSData
property NSArray : a reference to current application's NSArray

set theJSONDictionary to NSJSONSerialization's JSONObjectWithData:JSONData options:0 |error|:(missing value)
set timeSeries to theJSONDictionary's objectForKey:"Time Series (Daily)"

set prices to {} -- list of records for the prices, _not_ sorted
set theDates to timeSeries's allKeys() as list -- list of all dates in timeSeries

repeat with d in theDates
	set t to (timeSeries's objectForKey:d)
	set p to (t's objectForKey:"4. close")
	set end of prices to {date:d as string, price:p as string}
end repeat

-- prices is now a list of records containing the daily closing prices

on getUrlSource(urlStr)
	set theURL to current application's class "NSURL"'s URLWithString:urlStr
	set theData to current application's NSData's dataWithContentsOfURL:theURL
	return theData
end getUrlSource

IIUC, NSData dataWithContentsOfURL requires an NSURL so I get why the previous line has to create an NSURL. I am trying understand why it’s written as current application’s class “NSURL”'s in this quoted form.

At the time it was written there was a very popular scripting addition, Satimage that contained the term nsurl as part of its terminology. Using a quoted string was a way of avoiding a conflict that caused problems compiling. The problem has disappeared with the ban on third-party scripting additions.

1 Like

Thanks, @ShaneStanley. Good to know. :slight_smile: