Why does NSArrayController require module name in class name (in IB) for Swift?

I can't remember a single time when I needed to specify the program / module name when specifying the class name in the interface builder, other than this, and also the book (Big Nerd 5th ed. P162) says that I won't need to do this for Obj-C, but I have to for Swift, so why?

Context: I specify which class the NSArrayController will work with.

NSArrayController Class Name

+3


source to share


1 answer


Swift automatically creates impromptu namespaces for you (for example), prefixing your class Employee

with your module name. (You don't need to worry about this in your code, because since you usually refer to Employee

within that module, the compiler can understand your shorthand usage Employee

.) It can be useful to be explicit about this if your module defines the same symbol. as the other, for example MyProject.Array

vs. Swift.Array

...



Why is there a difference between languages? Because Objective-C just doesn't do this namespace, so each prefix their Objective-C classes with two- and three-letter codes to avoid name collisions.

+2


source







All Articles