Swift - import my quick class

This question is asked several times, but I can not find the right solution for my problem. I am trying to import my Player.swift class into my MainScene.swift (I used Cocos2D - SpriteBuilder to set up the project, now using Xcode).

This is my folder structure:

enter image description here

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

How do I import it correctly?

Thanks!

By the way, I'm new to Swift, so don't expect me to know all the terms

+7
import class xcode swift
source share
2 answers

You do not need to explicitly import files into Swift, as they are accessible globally through the project. If you want to access the methods or properties of the Player class , you can directly create an object of the Player class in the MainScene.Swift file and access it. eg var objPlayer = Player( )

+21
source share

There is no need to import quick classes for use in other quick access classes. They are available for use automatically.

In Swift, you can only import a module, for example. any wireframe, such as UIKit, MapKit, as shown below. You cannot import fast classes.

 import UIKit import MapKit 

Just be sure to select it for use for the purpose you are trying to use.

Check out the images below to find out more.

In this image, my HomeViewController.swift selected for use in the AutolayoutDemo module. enter image description here

In the following image, I unchecked the AutolayoutDemo check box for the DetailsViewController.swift class. enter image description here

So, now when I try to use the DetailsViewController compiler, I get an error, as shown below in the HomeViewController . enter image description here

+13
source share

All Articles