Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespaces and objective C

Tags:

objective-c

In c# I use namespaces in java I use packages. Is there a way to keep classnames short in objective c?

like image 741
Mel Avatar asked Apr 30 '11 13:04

Mel


People also ask

What is ns in nsobject?

The Foundation Kit, or just Foundation for short, is an Objective-C framework in the OpenStep specification. It provides basic classes such as wrapper classes and data structure classes. This framework uses the prefix NS (for NeXTSTEP).

What is namespace in Swift?

Namespace is a named region of program used to group variable, types and methods. Namespacing has following benefits: Allows to improve code structure by organizing the elements, which otherwise would have global scope, into the local scopes. Prevents name collision. Provides encapsulation.


1 Answers

Objective-C only has one, single global namespace. That is why you often see classes called SBJsonParser, so that the class name doesn't collide with other JsonParsers out there.

The general recommendation I have seen is to prefix your classes with either your initials or with a few initials for the project you are working on, the class name, then (sometimes) what "type" of class they are (as is the apparent convention for view controllers).

Honestly, I am right there with you Mel, I would be absolutely exhilarated for Objective-C to add some sort of namespacing feature, at least something to sort out classes a bit more (and a bit easier).

like image 127
Ryan Wersal Avatar answered Nov 02 '22 06:11

Ryan Wersal