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:
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
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.
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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With