[EDIT: Solved in Swift 5.3]
Swift 5.3 introduces the possibility to add resourses to the packages..
example:
.target( name: "challenges", dependencies: [], resources: [.copy("input.txt"), .copy("image.png")] )
However if anyone knows how to make it work for swift 5.2 pls advise!
[Original post]
I got a problem here.. I am probably missing something. I spent an hour trying dfferent things but this file is not seen by the system, no matter where I put it...
Any help is appreciated
I am trying to write a solution to an algorythm challenge using a Swift Package Executable.
I have an input.txt
file containing a long string of number...
I tried to import it in main like this:
let my inputString = try! String(contentsOfFile: "input.txt")
I get the Fatal Error at runtime:
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “input.txt” couldn’t be opened because there is no such file." UserInfo={NSFilePath=input.txt, NSUnderlyingError=0x10060af80 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
I tried to put the file in different places but it just does not work...
This is my package structure:
~/challenges
➜ tree
.
├── Package.swift
├── README.md
├── Sources
│ ├── challenges
│ │ └── main.swift
│ └── input.txt
└── Tests
├── LinuxMain.swift
└── challengesTests
├── XCTestManifests.swift
└── challengesTests.swift
4 directories, 7 files