Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 304
M Zeinstra Avatar asked Feb 05 '16 10:02

M Zeinstra


People also ask

What is import Swift?

Swift provides a way to group several files into a group, called module. Modules helps us do 2 things: reuse code, and encapsulate code. You just have to write a particular functionality once, and after putting it into a module, you can import that into different places and projects.

What is @_ exported in Swift?

The @_exported attribute starts with an underscore. That means it's a private Swift attribute. Not a feature, an implementation detail. In short, this attribute lets you export a symbol from another module as if it were from your module.

How do I import a bridging header in Swift?

Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File. Edit the bridging header to expose your Objective-C code to your Swift code: In your Objective-C bridging header, import every Objective-C header you want to expose to Swift.


1 Answers

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()

like image 183
Bhagyalaxmi Poojary Avatar answered Sep 20 '22 17:09

Bhagyalaxmi Poojary