0

I'm trying to use ObjC with JXA. Here is a simplest possible example:

ObjC.import('Foundation')
str = $.NSString.alloc.initWithUTF8String('foo')
console.log(str)

This code gives me an Error: TypeError: undefined is not an object (evaluating '$.NSString.alloc').

The same happens if I remove the 'import' line (as far as I understand symbols from the Foundation framework are available by default in JavaScript for Automation).

Why this happens?

Update: I'm using Big Sur (beta 2). Looks like something is broken in JXA<->ObjC bridge.

Thanks!

  • just guessing: maybe its str = $.(NSString.alloc()).initWithUTF8String('foo') even thinking you don't need the $ – Ol Sen Jul 16 '20 at 22:18
  • 1
    What version of macOS are you using and what editor are you using ? On _Script Editor_ in Catalina, you code works perfectly for me. – CJK Jul 18 '20 at 04:25
  • Ah, quite possible this is the issue: I'm testing Big Sur (bate 2). Looks like something is broken inside JXA<->ObjC bridge (I'm using Script Editor). Thanks for the info! – Valery Kondakoff Jul 20 '20 at 18:23
  • @ValeryKondakoff did you ever get to the bottom of this? I'm seeing the same issue on the Big Sur 11.2.1 – mrwest09 Feb 16 '21 at 06:54

0 Answers0