15

I'm writing an iOS app, "Best Korea". My organization name is "Srsly.co". I'm going to write re-usable "News" libraries that I'll use across my apps.

Each iOS app will have its own app-wide constants in a .h file, and the library code will have its constants as well in header files. I'll also have tests for each of these projects.

Is this the standard way of doing things?

In Ruby, Python, Java, etc., I'd set up namespaces along these lines:

co.srsly.bestkorea
co.srsly.bestkorea.test
co.srsly.newslib
co.srsly.newslib.test

As far as I can see, the Objective-C pattern is for each developer to choose two or three upper-case letters and prefix every class name with them.

So in my case, I'm thinking I'd choose BK as the app's classname prefix and NL for the news lib code? Am I thinking about this the right way?

EDIT: I'm considering not using namespacing at all in my application code as discussed here.

Community
  • 1
  • 1
Dogweather
  • 15,512
  • 17
  • 62
  • 81

2 Answers2

36

You're correct that Objective-C doesn't have built in support for namespaces, and the common solution is to use uppercase prefixes on each class. Note that Apple has stated that two letter prefixes are reserved for their use, so you should use three letter prefixes for your own classes. Otherwise, your suggested approach is the normal thing to do.

Andrew Madsen
  • 21,309
  • 5
  • 56
  • 97
  • 2
    Yeah that was news to me too. – abellina Mar 21 '13 at 03:45
  • Ah hah, so following the example on that page, I could use **SBK** as the app code prefix. – Dogweather Mar 21 '13 at 03:49
  • 1
    Yes, SBK seems like a good choice. For what it's worth, I use ORS for Open Reel Software (the name of my company). I think it's more common to use a prefix derived from your company name, rather than your app's name, but the choice is yours. – Andrew Madsen Mar 21 '13 at 03:52
2

There is no NameSpace in Objective-C as you are expecting in Java.

Objective-C uses class Prefix like NS, UI, CG, CF etc to safely remove name space collision.

And it would be better to use 3 letter Prefix for your class.

You should read this : What is the best way to solve an Objective-C namespace collision?

Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140