views:

3318

answers:

9

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

+21  A: 

It's the NextStep heritage

Olaf
+6  A: 

I believe it comes from "NextStep"

Corey Ross
+29  A: 

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 frameork. 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.

If you are writing an application, such that your code is the 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.

Barry Wark
+6  A: 

Like said, it is the NextStep (= NS) heritage. NeXT was the computer company that Steve Jobs formed after he quit Apple in 1985, and NextStep was it's operating system (UNIX based) together with the Obj-C language and runtime. Together with it's libraries and tools, NextStep was later renamed OpenStep (which was also the name on an API that NeXT developed together with Sun), which in turn later became Cocoa.

These different names are actually quite confusing (especially since some of the names differs only in which characters are upper or lower case..), try this for an explanation:

http://www.objectfarm.org/Activities/Publications/TheMerger/OpenstepConfusion.html

Gregor
+18  A: 

NeXT**S**TEP or NeXTSTEP/Sun depending on who you are asking since 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 Ne**X**T, 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.

David Holm
+1 I've also heard about the NeXT/Sun thing.
Outlaw Programmer
Thanks for the history. I didn't know about the NX->NS transition.
Barry Wark
It's sad that this answer didn't get marked the "correct" one.
Mitch Haile
+4  A: 

When NeXT were defining the NextStep API (as opposed to the NEXTSTEP operating system), they used the prefix NX, as in NXConstantString. When they were writing the OpenStep specification with Sun (not to be confused with the OPENSTEP operating system) they used the NS prefix, as in NSObject.

Graham Lee
+2  A: 

It is originated from NextStep.

Edit: It appears to be a dup - you can find thorough answers there.

Vladimir
It does make it look ugly =D
jpartogi
What do you mean?
Vladimir
NextStepString, NextStepMutableArray, etc. Fail.
Emil
+1  A: 

NextStep heritage

Domness
A: 

NS stands for NextStep and generally these NS header file present in Foundation.framework (Wow !A lot of NS).

raaz