Search code examples
xcodeswiftclassimport

Swift - Import my swift class


This question is asked several times, but I can't find the right solution for my problem. I'm trying to import my Player.swift class in my MainScene.swift (I've used Cocos2D - SpriteBuilder to setup the project; Now using Xcode).

This is my folder structure:

enter image description here

I've tried to use import Player; and import Player.swift;, but when I tried I got this error: No such module 'Player.swift'

How do I import it correctly?

Thanks!

By the way, I'm a beginner in Swift, so don't expect that I know all of the terms


Solution

  • You don't need to explicitly import files in Swift as they are globally available through the project. If you want to access the methods or properties of Player class, you can directly make object of Player class in MainScene.Swift file and can access to it. e.g var objPlayer = Player()