-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor resource helper to correctly get resource URLs when building…
… in Xcode (#132) * Move test fixtures into their own Resources directory * Update `ResourceHelper` to work with both Bundle.main and Bundle.module (Xcode and SPM) * Update Swift tools version in Package manifest to 5.5
- Loading branch information
Showing
11 changed files
with
127 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import Foundation | ||
|
||
// Find url of resource. | ||
// This is a workaround for SwiftPM, becasue SwiftPM is not yet support for include resources with targets.(https://bugs.swift.org/browse/SR-2866) | ||
// This is a workaround for Xcode, when testing from the Xcode project (not the SPM package) bundle.module is not available... | ||
|
||
struct ResourceHelper { | ||
static func url(forResource name: String, withExtension type: String) -> URL? { | ||
|
||
#if SWIFT_PACKAGE | ||
return Bundle.module.url(forResource: name, withExtension: type) | ||
#else | ||
// Xcode project | ||
let bundle = Bundle(for: NamedViewTests.self) | ||
if let url = bundle.url(forResource: name, withExtension: type) { | ||
return url | ||
} else if let realBundle = Bundle(path: "\(bundle.bundlePath)/../../../../SwiftCSVTests") { | ||
return realBundle.url(forResource: name, withExtension: type) | ||
} else { | ||
return nil | ||
|
||
// In Xcode, folders are stripped from the resources folder. | ||
var finalName = name | ||
var slashCharSet = CharacterSet() | ||
slashCharSet.insert("/") | ||
let parts = name.components(separatedBy: slashCharSet) | ||
if parts.count > 1 { | ||
finalName = parts.last! | ||
} | ||
return bundle.url(forResource: finalName, withExtension: type) | ||
#endif | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters