Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the NS prefix mean?

Many classes in Cocoa/Cocoa Touch have the NS prefix. What does it mean?

like image 735
Martin08 Avatar asked Jan 23 '09 17:01

Martin08


People also ask

What does NS stand for Apple?

It stands for NextSTEP, the operating system that Steve Jobs (caused to be) built after he was evicted from Apple. Objective-C and the NextSTEP API are the basis of the newer OpenSTEP and MacOS-X APIs.

What is Cocoa framework?

The Cocoa frameworks. The classes in Foundation provide objects and functionality that are the basis, or “foundation,” of Cocoa. The classes in Application Kit furnish the objects and behavior that your users see in the user interface, such as windows and buttons, and handle their mouse clicks and key presses.


3 Answers

The original code for the Cocoa frameworks came from the NeXTSTEP libraries Foundation and AppKit (those names are still used by Apple's Cocoa frameworks), and the NextStep engineers chose to prefix their symbols with NS.

Because Objective-C is an extension of C and thus doesn't have namespaces like in C++, symbols must be prefixed with a unique prefix so that they don't collide. This is particularly important for symbols defined in a framework.

If you are writing an application, such that your code is only likely ever to use your symbols, you don't have to worry about this. But if you're writing a framework or library for others' use, you should also prefix your symbols with a unique prefix. CocoaDev has a page where many developers in the Cocoa community have listed their "chosen" prefixes. You may also find this SO discussion helpful.

like image 76
Barry Wark Avatar answered Oct 07 '22 00:10

Barry Wark


It's from the NeXTSTEP heritage.

like image 38
Olaf Kock Avatar answered Oct 06 '22 23:10

Olaf Kock


NeXTSTEP or NeXTSTEP/Sun depending on who you are asking.

Sun had a fairly large investment in OpenStep for a while. Before Sun entered the picture most things in the foundation, even though it wasn't known as the foundation back then, was prefixed NX, for NeXT, and sometime just before Sun entered the picture everything was renamed to NS. The S most likely did not stand for Sun then but after Sun stepped in the general consensus was that it stood for Sun to honor their involvement.

I actually had a reference for this but I can't find it right now. I will update the post if/when I find it again.

like image 157
David Holm Avatar answered Oct 06 '22 22:10

David Holm