ObjC native call XFCNs

Here is where the magnanimous folks that create externals post them (.zip archives only please).

ObjC native call XFCNs

Postby witness » Sun Jan 26, 2014 4:26 pm

This is sort of a meta-XFCN. It lets you send Objective-C (Cocoa) messages from inside SuperCard. The (very bare) test project containing the XFCNs and a Readme with syntax and docs can be found here:

https://github.com/uliwitness/objc/releases/

This takes a bit of learning to do right, but if you're a seasoned SuperCarder and think about making the step to making your own XCMDs, this might be a good starting point.

As an example, if you wanted to keep lists of arbitrary strings, but can't set aside any character as an item delimiter, the code could look something like:

Code: Select all
framework "Foundation"
put objc("NSMutableArray","new") into theArray
repeat with x = 1 to 10
  put objcstr("My text,more text"&return&"even more text" && x) into cocoaString
  get objc(theArray,"addObject:",cocoaString)
end repeat

put objc(theArray,"count") into numItems
repeat with x = 1 to numItems
  put objc(theArray,"objectAtIndex:",x-1) into cocoaString -- -1 because Cocoa counts from 0.
  answer scstr(cocoaString)
end repeat

-- and once we're done with this array
get objc(theArray,"release")

You can get more info that helps understanding what this example does from Apple's documentation of NSMutableArray and NSArray: https://developer.apple.com/library/mac ... ectAtIndex:
Last edited by witness on Mon Jan 27, 2014 1:24 pm, edited 2 times in total.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are Everywhere..."
http://www.zathras.de
User avatar
witness
 
Posts: 57
Joined: Thu Jul 17, 2008 2:24 pm

Re: ObjC native call XFCNs

Postby vinnie-bob » Mon Jan 27, 2014 6:56 am

Hmmm…this makes me wonder…
I play with Applescript a fair amount, but not ObjC, so not so much with Applescript ObjC. But I wonder whether one can use an applescript which uses ObjC in SC using SC's applescript command?
------
vince
------
User avatar
vinnie-bob
 
Posts: 218
Joined: Sun Jul 06, 2008 10:55 am
Location: Des Moines, Iowa, USA

Re: ObjC native call XFCNs

Postby witness » Mon Jan 27, 2014 7:25 am

vinnie-bob wrote:Hmmm…this makes me wonder…
I play with Applescript a fair amount, but not ObjC, so not so much with Applescript ObjC. But I wonder whether one can use an applescript which uses ObjC in SC using SC's applescript command?


According to complaints I found on Google when investigating this, only AppleScript Studio and Automator were permitted to call methods, not regular AppleScript. There was a trick where you could use 'tell "Automator Helper"' or something like that to do it, too, but sandboxing promises to put the kibbosh on that in the future. So yeah, it's sorta possible.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are Everywhere..."
http://www.zathras.de
User avatar
witness
 
Posts: 57
Joined: Thu Jul 17, 2008 2:24 pm


Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest