Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@IngwiePhoenix
Created September 17, 2016 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IngwiePhoenix/5a9d915c91959a2e0a96198bdb94f125 to your computer and use it in GitHub Desktop.
Save IngwiePhoenix/5a9d915c91959a2e0a96198bdb94f125 to your computer and use it in GitHub Desktop.
Mac app structure

A Mac Application is structured as a bundle. Assume you have a Hello World application in Objective-C, the most "by-hand" way to build the bundle would be so:

Code:

// Copied from: http://macosx-programming.blogspot.de/2011/09/simple-gui-hello-world-using-cocoa.html
#include <Cocoa/Cocoa.h>

int main(int argc, const char** argv)
{
 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
 [NSApplication sharedApplication];
 
 NSRunAlertPanel(@"Testing Message Box",
     @"Hello, World!",
     @"OK", NULL, NULL);
 [pool release];
 return 0;
}

Build (assuming the code is in hello.m):

$ nano hello.m
$ clang hello.m -o hello -framework Cocoa
$ mkdir -p Hello.app/Contents/MacOS
$ cp hello Hello.app/Contents/MacOS/hello

Navigate to the folder where you made the Hello.app folder, and you'll notice it actually can be started. If not, chmod +x it.

Important: Normally, a Mac App uses a Info.plist file to determine settings liek the display name, executable name, version and more. If none is given, the executable is expected to have the same name as the app - case insensitive.

Hope it helped =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment