I'm not sure which is the right way, right now I'm just calling exit(0) when a user clicks on the exit button.
exit(0)
Use NSApplication's terminate method. For example:
NSApplication
terminate
[NSApp terminate:self]
Documentation is available here.