Reputation: 4107
I would a way to have test data from JSON resources or swift files only for DEVELOPMENT. (I don't want to include them in release)
I have tried to use files without target membership but it does not work. Also, I tried using the DEBUG define to wrap the code but without luck.
Example:
struct BasketView_Previews: PreviewProvider {
static var item: Item = {
let item: Item = load(filename: "testItem")
// or
let item: Item = load(data: Data(testItemJSONString.utf8))
return testItem
}()
static var previews: some View {
MyView(item: item)
}
}
#endif
Upvotes: 2
Views: 718
Reputation: 4107
Steps:
Upvotes: 4
Reputation: 535306
You are looking for the DEVELOPMENT_ASSET_PATHS
build setting. Resources at the designated paths are not present when you archive, so they won't be included in your distribution.
Here's the relevant paragraph from my book:
New in Xcode 11, the Development Assets build setting lets you specify a path for resources that won't be included in an archive build. In this way your app can include resources such as default data during development and testing, without those resources polluting the final built app. These can be individual resources or entire asset catalogs. A neat approach is a folder-linked group in the Project navigator: put your development-only resources into that group, and specify the path to the corresponding folder in Development Assets.
Upvotes: 2