[swift-users] How to write a test against fixture resources from generated xcodeproj test bundle?
Toshihiro Suzuki
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)
Target: x86_64-apple-macosx10.9
$ 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
bundle?
Thanks,
Toshihiro Suzuki
--
Toshihiro Suzuki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170610/5d900635/attachment.html>
More information about the swift-users
mailing list