Home > Net >  Programatically checking for NSBundle in macOS
Programatically checking for NSBundle in macOS

Time:06-24

I am building my application for macOS using CMake. My application can either be MACOSX_BUNDLE i.e. generated as a .app through CMake or it can even be a Unix-style executable. Is there a programmatic way in Obj-C to check if the executable is Unix-Style or NSBundle?

CodePudding user response:

Assuming you use Foundation and Objective-C in both binaries it is possible to check using NSBundle properties, because bundle instance itself will created on both cases (it just references to folder around executing binary), but bundle info will be present only on macOS.

So here is possible approach:

if (nil != [[NSBundle mainBundle] bundleIdentifier]) {
// macOS code here
} else {
// linux code here
}
  • Related