I have the following method in my app delegate. My app delegate is of class NSObject. When I try to log aChild’s className or use componentsSeparatedByString I get the errors listed below. I don’t know why I’m getting these errors. I know I’m overlooking something simple, I just don’t know what it is.
on readFromTextFile_(sender)
set theFile to POSIX path of (choose file with prompt "Choose file:" of type "txt")
set theChildren to paragraphs of (read theFile as text)
repeat with aChild in theChildren
log aChild
log aChild's className() -- A
set theValues to (aChild's componentsSeparatedByString_(tab)) as list -- B
set theChildValues to items 1 thru 12 of theValues as list
set theDayValues to items 13 thru end of theValues as list
log theChildValues
log theDayValues
end repeat
end readFromTextFile_
A: -[DayCare_ProviderAppDelegate readFromTextFile:]: unrecognized function className. (error -10000)
B: -[DayCare_ProviderAppDelegate readFromTextFile:]: unrecognized function componentsSeparatedByString_. (error -10000)
Thanks in advance,
Brad Bumgarner
Model: Macbook (mid 2010)
AppleScript: xCode 3.2.6
Browser: Safari 7536.25
Operating System: Mac OS X (10.7)
Hi,
the class of aChild is AppleScript text, it’s not an ObjC object, so the method className() fails.
And therefore also the method componentsSeparatedByString_() fails.
Either you create an NSString object
set aChildAsObject to current application's NSString's stringWithString_(aChild)
set theValues to (aChildAsObject's componentsSeparatedByString_(tab)) as list -- B
or use Cocoa’s equivalent of read file
set theFile to POSIX path of (choose file with prompt "Choose file:" of type "txt")
set theText to current application's NSString's stringWithContentsOfFile_encoding_error_(theFile, current application's NSASCIIStringEncoding, missing value)
set theChildren to theText's componentsSeparatedByCharactersInSet_(current application's NSCharacterSet's newlineCharacterSet())
repeat with aChild in theChildren
.
Thanks Stefan,
I knew I was overlooking something simple. The componentSeparatedByString: was originally in ChildClass (a custom class) and the data passed to it was automatically coerced to a NSString. When I moved to the code to the app delegate the data wasn’t (obviously) being coerced.
If I did this more than just as a hobby, I’d probably take the dive and learn Obj-C. :lol:
Thanks again,
Brad Bumgarner
[edit]: I went with the reading the file proposal.
It’s worth it, and it makes it easier to understand the odds and ends of the AppleScriptObjC framework