Home > Enterprise >  How to access a .swift file in a different folder from main.swit file on replit for Swift?
How to access a .swift file in a different folder from main.swit file on replit for Swift?

Time:08-18

I've been using replit to program using Swift and I have divided the code into different swift files and respective folders how to access these files from the main.swift file. the import option isn't applicable and the replit error output is that such a class can't be found in the scope. The classes are respective methods are declared as public too.

CodePudding user response:

When you try to compile multiple files on replit, you need to manually add other files to the compile configuration.

To do so, on the file directories, there's a three dot icon you can click, where you can select Show hidden files: enter image description here

Then you would be able to see a hidden config file called .replit, where you can append other files needed to the compile:

compile = ["swiftc", "-o", "main", "main.swift", "other_file.swift"]

Or compile with all files ended with .swift extension:

compile = "swiftc -o main $(find . -type f -name '*.swift')"
  • Related