when I use Swift, In current file for example main.swift, I import a class defined in an other file, for example B.swift in the sub-folder which is in the same folder with main.swift.The instruction of catalog is main.swift and sub-folder/B.swift.I always receive an error :“no such module”, why???
link your repl on to the chat so i can see it.
thx
According to Stack Overflow:
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 inMainScene.Swift
file and can access to it.e.g var objPlayer = Player()
So for your use case:
var B = SubFolder.B()
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()
There is no need to import swift classes to use in other swift classes. They are available to use automatically.
In Swift you can only import module, e.g. any framework like UIKit, MapKit as below. You cannot import swift classes.
import UIKit
import MapKit
Just make sure its selected to use in target in which your are trying to use.
Check below images for more idea.
In this image my HomeViewController.swift
is selected to use in AutolayoutDemo
module.
In below image I have unchecked AutolayoutDemo
module for the class DetailsViewController.swift
.
So now onwards when I will try to use the DetailsViewController
compiler will give me error as below image in HomeViewController
.
you can test the method you give, I tried, but it is the same error.
Please test it in replit.
Please test your idea in my repl example.