Unrecognized function componentsJoinedByString_.

Working through “A Class of Our Own” in ApplescriptObjC Explored 4.0.1, on page 56, adding the NSArray method, I am getting a runtime error:

I can’t figure out what I am doing wrong. My handler looks like:


    on saveDataAsTabbedText_(sender)
        set allAds to theArrayController's arrangedObjects()
        tell allAds to set adLines to (valueForKey_("adAsTabbedText")) as list
        set tabbedText to (adLines's componentsJoinedByString_(return)) as text
        log tabbedText
    end saveDataAsTabbedText_

Prior to adding componentsJoinedByString: things were working fine. Probably an obvious oversight.

You are coercing your NSArray into an applescript list, which is unecessary and perhaps the cause of your problem, because componentsJoinedByString_ expects and NSArray or NSMutableArray since it is an NSArray instance method.

Try this (untested) :

on saveDataAsTabbedText_(sender)
set allAds to theArrayController's arrangedObjects()
tell allAds to set adLines to (valueForKey_("adAsTabbedText"))
set tabbedText to (adLines's componentsJoinedByString_(return)) --RETURNS AN NSString OBJECT
log tabbedText
end saveDataAsTabbedText_

Is the allAds object extracted from the key “adAsTabbedText” an NSArray? Or an NSString with a bunch of strings separated by a tab char? Then you’d need to do this if it’s the case (again, untested) :

on saveDataAsTabbedText_(sender)
set allAds to theArrayController's arrangedObjects()
set adLines to allAds's (valueForKey_("adAsTabbedText"))'s componentsSeparatedByString_(tab) --RETURNS AND NSArray OBJECT
set tabbedText to (adLines's componentsJoinedByString_(return)) --RETURNS AN NSString OBJECT
log tabbedText
end saveDataAsTabbedText_

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

Oh, I knew I just wasn’t seeing something. I had added some parens that broke the class association in the line:


tell allAds to set adLines to (valueForKey_("adAsTabbedText")) as list

so adLines was a list rather than an NSArray. Somehow that was part of some earlier code. I so carefully checked the snipet and didn’t see it until I went out for a bike ride and came back!

Thanks for your time but all is good now with:


tell allAds to set adLines to valueForKey_("adAsTabbedText")

instead.