It is very easy to create a custom swift or objective-c class in Xcode project, this article will tell you how to do it step by step.
1. Create Custom Class In Xcode Project Steps.
- Click File —> New —> File menu item in the Xcode top menu bar.
- Then select iOS tab at top tab bar of the popup window, then select Cocoa Touch Class item in the Source section.
- Click Next button to go to next dialog window. Input class name, choose parent class, select Swift or Objective-C in the language drop down list, then click Next button.
- Choose a folder to save the custom class related files.
- Click Create button to create the custom class related files, then you can see the files added in left Xcode project navigator panel.
2. How To Reference And Use The Custom Swift Class.
Now you can reference and use above custom swift class in other swift file of your Xcode project. You do not need to import the custom class into other swift file, just invoke the custom class’s initializer function to use it like below.
// Create an instance of class TestObjectiveCClass. var testVar : TestObjectiveCClass = TestObjectiveCClass() // Invoke above variable's function. testVar.abc...()