How To Create Custom Class In Xcode Project

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.

  1. Click File —> New —> File menu item in the Xcode top menu bar.
    xcode file new file menu item
  2. Then select iOS tab at top tab bar of the popup window, then select Cocoa Touch Class item in the Source section.
    xcode ios cocoa touch class template
  3. 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.
    input cocoa touch class name and select objective-c coding language
  4. Choose a folder to save the custom class related files.
  5. 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...()

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.