Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Jul 14, 2020
1 parent 4273674 commit ffd67d9
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
[![Github actions badge](https://badgen.net/github/checks/eonist/ResourceHelper?icon=github&label=Builds)](https://github.com/eonist/ResourceHelper/actions)
[![codebeat badge](https://codebeat.co/badges/6704b945-11ad-43ad-b290-ebe32edd04f0)](https://codebeat.co/projects/github-com-eonist-resourcehelper-master)

# ResourceHelper
Enables you to use .bundle and other resources with SPM Unit-tests.
# 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

This will ONLY work for unit testing as the executable is loaded by then. As such, using this within your app's source code will NOT work. However, [Swift 5.3](https://github.com/apple/swift-evolution/blob/master/proposals/0271-package-manager-resources.md) will support adding assets along with packages.

If you want to add assets to your source code, you can do so by creating a directory called `Resources` in the root folder of your package. Inside `Resources`, add all the assets you need. After adding your package to your app's target, add the `Resources` folder to your `Copy Bundle Resources` build phase.
### 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
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 enter https://github.com/eonist/ResourceHelper
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.

Expand All @@ -26,21 +32,11 @@ If you are using `Package.swift`, you can also add `ResourceHelper` as a depende
let package = Package(
name: "TestProject",
dependencies: [
.package(url: "https://github.com/eonist/ResourceHelper", from: "1.0.0")
.package(url: "https://github.com/eonist/ResourceHelper.git", .branch("master"))
],
targets: [
.target(name: "TestProject", dependencies: ["ResourceHelper"])
]
)

```

### Usage:

Make sure the assets you want to use are in the same directory as your `Package.swift`

```swift

ResourceHelper.projectRootURL(projectRef: #file, fileName: "payload.json").path // /Users/John/Documents/AwesomeApp/payload.json

```

0 comments on commit ffd67d9

Please sign in to comment.