bits about life, coding and stuff
Missing namespaces are a a huge problem in objectivec – something that can’t be solved easily. And the more third-party libs you use, the more trouble it gets.
Imagine, I had to rename my model classes after linking with the MessageUI Framework (InApp Email) because “Message” and “Account” classes are used by Apple. Private ones, not documented, but there. And they conflict with your classes, at least if you use Core Data.
Lesson learned: prefix everything! (There’s a reason it’s NSString, not String, or CFRect, not Rect…)
There’s more to read on this on StackOverflow
The fundamental difference between the C and Objective-C runtimes is, as I understand it, when libraries are loaded, the functions in those libraries contain pointers to any symbols they reference, whereas in Objective-C, they contain string representations of the names of thsoe symbols. Thus, in your example, you can use dlsym to get the symbol’s address in memory and attach it to another symbol. The other code in the library still works because you’re not changing the address of the original symbol. Objective-C uses a lookup table to map class names to addresses, and it’s a 1-1 mapping, so you can’t have two classes with the same name. Thus, to load both classes, one of them must have their name changed. However, when other classes need to access one of the classes with that name, they will ask the lookup table for its address, and the lookup table will never return the address of the renamed class given the original class’s name.
And there’s even more. The compiler has some problems where it want’s to be backward compatible with new @optional categories. My current problem was this:
TTThumbsViewControllerDelegate? I’m not using that in this class, nor any class used by this class. Yet the compiler warns me about something. I’d be lost without google on this.
“It’s likely an artifact of the code wanting to be backwards-compatible with a time before @optional was available (and adopting a formal protocol required implementing all of its methods).” – Otto from StackOverflow.
Yet fixing this is fairly easy (without disabling warnings for the file
. Just cast the allocated memory to the specific type, this helps the compiler keeping track of what you wanna do.
_statusPicker = [(LoginStatusPicker *)[LoginStatusPicker alloc] initWithDelegate:self];
That said, ObjC is still far superior to C/C++. No language is perfect…
Related posts:
2 Responses to Namespaces and ObjectiveC
Dominik
February 25th, 2010 at 8:40 pm
The solutions to your problems are called naming conventions
iOS development for .NET developers at nateperry.org
April 21st, 2011 at 9:01 pm
[...] No equivalent. Use prefixes. [...]