-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix SwiftUI preview crashes when accessing assets from a nested Swift Package. #171
Conversation
Thanks for the PR, @y-okudera. I will review the PR by the end of the week. |
@subdan |
{% if resourceBundleNames %} | ||
private extension Foundation.Bundle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have the same private extension Foundation.Bundle...
code in four Stencil files. Avoid code duplication by extracting duplicated code in a separate file and use Stencil's include
keyword.
@@ -105,6 +105,7 @@ struct Params: Decodable { | |||
let xcassetsPath: URL | |||
let xcassetsInMainBundle: Bool | |||
let xcassetsInSwiftPackage: Bool? | |||
let resourceBundleNames: [String] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter must be optional to support backward compatibility. If this parameter will be required, current FigmaExport users will need to specify a value to this property. Moreover a lot of users don't store xcassets in the Swift Package and won't specify a value for this property.
Co-authored-by: Daniil Subbotin <robots@subdan.ru>
@subdan |
// Bundle should be present here when the package is linked into a framework. | ||
Bundle(for: BundleFinder.self).resourceURL, | ||
// Bundle should be present here when the package is used in UI Tests. | ||
Bundle(for: BundleFinder.self).resourceURL?.deletingLastPathComponent(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test-code must not be included in release build. Use #if DEBUG
.
// Bundle should be present here when running previews from a different package (this is the path to "…/Debug-iphonesimulator/"). | ||
Bundle(for: BundleFinder.self).resourceURL?.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent(), | ||
Bundle(for: BundleFinder.self).resourceURL?.deletingLastPathComponent().deletingLastPathComponent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
Thanks for the re-review, @subdan . I will fix the stencil file by the end of the week. |
Hi, Thank you for an amazing utility!
Fixed SwiftUI preview crashes when accessing assets from a nested Swift Package.
Crash Info
I have two modules the Presentation and the DesignSystem.
The DesignSystem module has Color extension generated by figma-export.
The Presentation module has SwiftUIView that using Color extension of DesignSystem. As soon as it touches the assets from the DesignSystem module, the preview crashes.
Reference
https://developer.apple.com/forums/thread/664295?login=true#reply-to-this-question