-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash when accessing bundle resources in Previews (#6008)
* Fix crash when accessing bundle resources in previews * Lint * Remove previous implementation that didn't work * Run lint * Remove warnings * Better fix * Add fixture * Lint * Rename fixture to app_with_previews * Add acceptance test for the fixture * Improve comment --------- Co-authored-by: Daniele Formichelli <df@bendingspoons.com>
- Loading branch information
1 parent
0e88426
commit 89896af
Showing
17 changed files
with
138 additions
and
39 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
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
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
19 changes: 19 additions & 0 deletions
19
fixtures/app_with_previews/PreviewsFramework/Sources/TestView.swift
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import ResourcesFramework | ||
import SwiftUI | ||
|
||
struct TestView: View { | ||
var body: some View { | ||
VStack { | ||
Button("Click to read file from bundle") { | ||
text = readFileFromBundle() | ||
} | ||
Text(text) | ||
} | ||
} | ||
|
||
@State var text = "-" | ||
} | ||
|
||
#Preview { | ||
TestView() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import ProjectDescription | ||
|
||
let project = Project( | ||
name: "PreviewsFramework", | ||
targets: [ | ||
.target( | ||
name: "PreviewsFramework", | ||
destinations: .iOS, | ||
product: .framework, | ||
bundleId: "io.tuist.previewsframework", | ||
sources: "PreviewsFramework/Sources/**", | ||
dependencies: [ | ||
.external(name: "ResourcesFramework"), | ||
] | ||
), | ||
] | ||
) |
25 changes: 25 additions & 0 deletions
25
fixtures/app_with_previews/ResourcesFramework/Package.swift
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// swift-tools-version: 5.9 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ResourcesFramework", | ||
platforms: [.iOS(.v15), .macOS(.v14)], | ||
products: [ | ||
.library( | ||
name: "ResourcesFramework", | ||
type: .static, | ||
targets: [ | ||
"ResourcesFramework", | ||
] | ||
), | ||
], | ||
targets: [ | ||
.target( | ||
name: "ResourcesFramework", | ||
resources: [ | ||
.process("Resources"), | ||
] | ||
), | ||
] | ||
) |
6 changes: 6 additions & 0 deletions
6
fixtures/app_with_previews/ResourcesFramework/Sources/ResourcesFramework/BundleReader.swift
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
public func readFileFromBundle() -> String { | ||
let path = Bundle.module.url(forResource: "file", withExtension: "txt")! | ||
return try! String(contentsOf: path) | ||
} |
1 change: 1 addition & 0 deletions
1
fixtures/app_with_previews/ResourcesFramework/Sources/ResourcesFramework/Resources/file.txt
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// swift-tools-version: 5.9 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "project_with_previews_crash", | ||
dependencies: [ | ||
.package(path: "../ResourcesFramework"), | ||
] | ||
) |
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
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ final class CreateFileTests: XCTestCase { | |
func test_example() { | ||
XCTAssertEqual("CreateFile", "CreateFile") | ||
} | ||
} | ||
} |