I’m going through various Obj-c code and trying to translate in ASOC for future use. I came across an Obj-C sample and seems to be having trouble translating it. Any help would be appreciated. Could it be that white space in not the same as a blank space?
I get the standard “unrecognized selector set to instance error -10000”
script runScript
set aString to current application's NSApp's passedValue() as text
set theWhiteSpace to current application's NSCharacterSet's whitespaceCharacterSet()
set theScannerOutput to current application's NSString's alloc()'s initWithString_(aString)'s autorelease()
set theTempString to current application's NSString's alloc()'s init()'s autorelease()
theScannerOutput's scanUpToCharactersFromSet_(theWhiteSpace)'s intoString_(theTempString)
return theTempString
end script
tell application "ASObjC Runner" to set theResult to run the script {runScript} passing "How much wood can a woodchuck chuck?" with result returned
log theResult
That line is wrong. You want “current application’s NSScanner’s alloc()'s initWithString_(aString)”. Or, you could use “current application’s NSScanner’s scannerWithString_(aString)” Also, you don’t really need the autoreleases unless your working in a non-garbage collected environment.
the method is called scanUpToCharactersFromSet_intoString_(), a single method
the return value of the scanner method is a pointer to an object, so you must pass the keyword reference
set theWhiteSpace to current application's NSCharacterSet's whitespaceCharacterSet()
set theScannerOutput to current application's NSScanner's alloc()'s initWithString_(aString)
set theResult to theScannerOutput's scanUpToCharactersFromSet_intoString_(theWhiteSpace, reference)
return item 2 of theResult -- item 1 is the boolean result of the method