The absence of namespace is always being criticized by developers using Objective-C. That is why the crowd cheered when Craig announced there would be namespace in Swift. In app development, all code and referenced static library will be linked together into the same binary. Without namespace, once two classes happen to be the same name, it will not compile due to the name conflicting.

Objective-C developers got used to adding a prefix to the class name. Apple reserved the NS and UI prefix for main classes in Cocoa/Cocoa Touch. Frameworks are also prefixed, such as SK for StoreKit and CG for CoreGraphic. The Objective-C community follows this rule and put the abbreviation of the name of the developer or company there. So we have the name of AFNetworking or MBProgressHUD.

This could solve some problems, but cannot claim to be elegant or perfect. Another potential problem is using third party frameworks. The framework you want to use might use other libraries without changing the class name. Once two frameworks are referring a same third party library, you cannot get it compiles as well.

In Swift, thanks to namespace, we can have the same name for a class if they come from two namespace. It is not the same as C#, in which namespace is declared explicitly and containing additional code with braces. Namespace in Swift is based on the module. Every module represents a namespace in Swift. That means two classes with the same name are forbidden in one target. It would be a good habit to put different things into different target. With the newly added Cocoa/Cocoa Touch framework target in Xcode 6, we can get it easier than ever before.

// MyFramework.swift
// This class exists in MyFramework.framework
public class MyClass {
    public class func hello() {
        print("hello from framework")
    }
}

// MyApp.swift
// This class exists in app's target
class MyClass {
    class func hello() {
        print("hello from app")
    }
}

If there is any conflict in context when using these two classes, we are required to add the module name before it. For example, when we write the code below in a file in app's target:

MyClass.hello()
// hello from app

MyFramework.MyClass.hello()
// hello from framework

The first MyClass refers to the one in the app target, since this code itself is in the app's target. While in the second one, we just have to specify the MyFramework to make it calling the correct method of MyClass in MyFramework.

Another way beside of using namespace is nesting types. Make a wrapper for the classes with same name by using different structs, to avoid the conflicting. By doing this, we can separate these classes without multiple module as well:

struct MyClassContainer1 {
    class MyClass {
        class func hello() {
            print("hello from MyClassContainer1")
        }
    }
}

struct MyClassContainer2 {
    class MyClass {
        class func hello() {
            print("hello from MyClassContainer2")
        }
    }
}

When using:

MyClassContainer1.MyClass.hello()
MyClassContainer2.MyClass.hello()

It is not the same as a traditional namespace concept in other languages. Namespace in Swift is more like a promotion to developers. However, if we can follow the rules, we can avoid quite a lot of annoying issues, especially the naming issues. At least, we can omit the meaningless prefix from types in Swift.