[swift-users] How to write a test against fixture resources from generated xcodeproj test bundle?
t.suzuki326 at gmail.com
Fri Jun 9 21:02:09 CDT 2017
Hi Swift Community,
I'm Toshihiro Suzuki and have a question about Swift Package Manager.
I'm trying out with new Xcode9-beta.
When I generate a new xcodeproj like this, `Resources` directory is
imported as a folder reference in xcodeproj.
$ swift -version
Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
$ swift package init --type library
$ mkdir -p Resources/Fixtures/
$ touch Resources/Fixtures/test.txt
$ swift package generate-xcodeproj
When I open the xcodeproj and hit Cmd+U, I want to access test.txt with
code like this.
let path = Bundle(for: Swift4sampleTests.self).path(forResource:
"test.txt", ofType: nil)!
let data = Data(contentsOf: URL(string: path)!)
To make it work, I need to manually
- add Resources/ as a group, instead of folder reference.
- add "Copy Files Phase" in Build Phase to copy test.txt as "Resources".
Can SwiftPM handle this use-case automatically?
Or is there a way to access test resources from generated xcodeproj test
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users