Can we access and use native OS X classes within Electron?


#1

Hi,

For example, can we use NSFileManager and other classes?

Thanks,
Behrang


#2

No.
NSFileManager is part of the cocoa framework which is written in Objective C.
Electron is based on Javascript though and therefore not easily compatible with Objective-C code. However you can use all the functions available via nodejs (which a major part of Electron is based on): https://nodejs.org/api/fs.html#fs_file_system to work with the filesystem.


#3

Just because it is a JavaScript based framework it doesn’t mean it can’t access native classes. Tint2 can. So do RubyMotion and RoboVM. As long as a bridge is implemented for the language it can be done.

But thanks, I got the answee I was looking for.


#4

That’s why I said it is not easily compatible. :wink:
If you really need/want to call cocoa functions, you could take a look at nodeObjC
It seems to be well maintained.

That said, in terms of filesystem operations, it’s probably more straightforward and resource friendly to just use the nodejs functions. You would also sacrifice multi-platform support if you used OSX-only functions inside your app in important code parts.