https://github.com/eonist/resourcehelper
Enables you to use .bundle and other resources with SPM Unit-tests
https://github.com/eonist/resourcehelper
asset bundle ci continuous-integration files spm swift-package-manager testing unit-testing
Last synced: 19 days ago
JSON representation
Enables you to use .bundle and other resources with SPM Unit-tests
- Host: GitHub
- URL: https://github.com/eonist/resourcehelper
- Owner: eonist
- Created: 2020-01-04T12:31:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-09T14:00:44.000Z (over 3 years ago)
- Last Synced: 2025-03-27T23:24:50.542Z (about 1 month ago)
- Topics: asset, bundle, ci, continuous-integration, files, spm, swift-package-manager, testing, unit-testing
- Language: Swift
- Homepage:
- Size: 28.3 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README



[](https://github.com/apple/swift)
[](https://codebeat.co/projects/github-com-eonist-resourcehelper-master)
# Features
- Enables you to use .bundle and other resources with SPM Unit-tests. (Perfect for Github action CI)
- Enables you to also use the same code in Xcode unit tests### Example code:
```swift
// The temp.bundle folder can be in the root of your project (same directory as your `Package.swift`)
// iOS can only add resources inside .bundle folders
// macOS can only read files within its SandBox. Turn off Sandbox in info.plist (Using swift 5.3 and native spm assets is a better option here)
let path: String = ResourceHelper.projectRootURL(projectRef: #file, fileName: "temp.bundle/payload.json").path
Swift.print("path: \(path)") // Users/John/Documents/AwesomeApp/temp.bundle/payload.json
```**Note:** [Swift 5.3](https://github.com/apple/swift-evolution/blob/master/proposals/0271-package-manager-resources.md) has support for adding assets with SPM, although a bit cumbersome. here is a tutorial 😅: [https://medium.com/better-programming/how-to-add-resources-in-swift-package-manager-c437d44ec593](https://medium.com/better-programming/how-to-add-resources-in-swift-package-manager-c437d44ec593)
## Installation
`ResourceHelper` is available using the [Swift Package Manager](https://swift.org/package-manager/):
Using Xcode 11, go to `File -> Swift Packages -> Add Package Dependency` and search for ResourceHelper or enter: https://github.com/eonist/ResourceHelper
If you are using `Package.swift`, you can also add `ResourceHelper` as a dependency easily.
```swift
let package = Package(
name: "TestProject",
dependencies: [
.package(url: "https://github.com/eonist/ResourceHelper.git", .branch("master"))
],
targets: [
.target(name: "TestProject", dependencies: ["ResourceHelper"])
]
)```