Scene:
The class name in the project is too long to distinguish it from the file name, and if a module has more classes, it is difficult to get a more elegant name. To make the module name readable, it is common practice to add a module prefix. However, if the module also has sub-modules, if you continue to follow this method, the file name will be particularly long.
1. First level (Me Module)
Memaincontroller
Meeditcontroller Meaboutcontroller
2. Level Two (Me > Profile Module)
Meprofilechangepasswordcontroller
Meprofilechangeavatorcontroller
This time the name of the file is too long to be elegant, think of our intention to take such a long name, just want to reach the project in the class name unique, readable non-conflicting
NameSpace
Swift's namespace, learned C + +, PHP know, and they are very different. The Swift namespace is based on the module
Instead of explicitly specifying in the code, each module represents a namespace in Swift. In other words, the type name in the same target
Still can't be the same. When we do app development, the content that is added by default to the app's main target is in the same namespace.
1. Different target, here is not the burden here, please refer to my reference > namespace below for a detailed explanation
2. How do I achieve this namespace effect in a project?
1. Include with struct
//
struct Packageone {
}extension Packageone { class class { var name:string init (name:string) { self.name = name } } }print ("\ (PackageOne.Class.self)") Let TMP = Packageone.class (name: "Hell") print (TMP)//class with class TestClass {} Extension TestClass { class MyClass { var name:string init (name:string) { self.name = name } }} Let test = Testclass.myclass (name: "Test") print (test)
From the code above, enlighten us on the specific application in the project:
1. For view
Project use: struct Memodule { struct views{} struct viewcontrollers{}}//This is a viewextension memodule.views { Class edit:uiview{ }}extension memodule.views { class Update:uiview { }}
2. For Viewcontroller
This is a controllerextension memodule.viewcontrollers { class Edit:uiviewcontroller { }}extension memodule.viewcontrollers { class Update:uiviewcontroller { } }
Use Naspace to make the class name unique, the above two cases, for the organization of the folder we will
Memodule>views>edit> Edit.swift
Memodule> Views>update>update.swift
Memodule>viewcontrollers>edit>editcontroller.swift
Memodule>viewcontrollers>update>updatecontroller.swift
Makes the file unique.
Reference:
1. Namespaces
2. How do I use the Namespace in Swift?
Swift's namespace