-
Notifications
You must be signed in to change notification settings - Fork 54
Accept asset catalog entries in localResources #465
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
Open
yusuftor
wants to merge
10
commits into
develop
Choose a base branch
from
feat/local-resources-asset-catalog
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dc89136
Accept asset catalog entries in localResources
yusuftor 61d38f2
Back-fill CatalogAsset MIME type on iOS 13
yusuftor 45fa834
Show non-image catalog assets in debug view, drop unused import
yusuftor db63ec1
Use trailing closure for entitlements dict uniquing
yusuftor 3cd051d
Drop unused UIKit import; preserve catalog entries on ObjC set
yusuftor 2d8f980
Revert ObjC setter merge; keep simple replace semantics
yusuftor 5b23f97
Fall back to Image Set when CatalogAsset has no Data Set
yusuftor e7f5c50
Try UIImage before NSDataAsset to avoid CoreUI warning
yusuftor c65894e
Conform UIImage to AssetResource
yusuftor de085d5
Mirror scheme handler order in debug catalog preview
yusuftor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
| // | ||
| // AssetResource.swift | ||
| // SuperwallKit | ||
| // | ||
| // Created by Yusuf Tör on 24/04/2026. | ||
| // | ||
|
|
||
| import Foundation | ||
| #if canImport(UIKit) | ||
| import UIKit | ||
| #endif | ||
|
|
||
| /// A type that can be registered against ``SuperwallOptions/localResources`` and | ||
| /// served to the paywall webview via the `swlocal://` URL scheme. | ||
| /// | ||
| /// Conforming types: | ||
| /// - `URL` — a file on disk. | ||
| /// - `UIImage` — re-encoded as PNG when served to the webview. | ||
| /// - ``CatalogAsset`` — a deferred lookup against an `.xcassets` entry. Handles | ||
| /// both Image Sets and Data Sets (video, Lottie JSON, etc.). | ||
| /// | ||
| /// ```swift | ||
| /// options.localResources = [ | ||
| /// "hero-image": Bundle.main.url(forResource: "hero", withExtension: "png")!, | ||
| /// "logo": UIImage(named: "Logo")!, | ||
| /// "hero-video": CatalogAsset(name: "HeroVideo") | ||
| /// ] | ||
| /// ``` | ||
| public protocol AssetResource {} | ||
|
|
||
| extension URL: AssetResource {} | ||
|
|
||
| #if canImport(UIKit) | ||
| extension UIImage: AssetResource {} | ||
| #endif | ||
|
|
||
| /// An entry in an asset catalog (`.xcassets`). | ||
| /// | ||
| /// Resolved at load time by trying `UIImage(named:in:compatibleWith:)` first | ||
| /// (Image Set, re-encoded as PNG), then falling back to | ||
| /// `NSDataAsset(name:bundle:)` (Data Set, raw bytes preserved with no | ||
| /// re-encoding). | ||
| /// | ||
| /// Use a Data Set for non-image content (video, Lottie JSON, etc.) or when | ||
| /// you need lossless bytes. Image Sets work as-is for typical paywall imagery | ||
| /// like logos and icons. | ||
| public struct CatalogAsset: AssetResource { | ||
| /// The name of the data asset as it appears in the asset catalog. | ||
| public let name: String | ||
|
|
||
| /// The bundle that contains the asset catalog. | ||
| public let bundle: Bundle | ||
|
|
||
| /// Creates a reference to a Data Set entry in an asset catalog. | ||
| /// | ||
| /// - Parameters: | ||
| /// - name: The name of the data asset as it appears in the asset catalog. | ||
| /// - bundle: The bundle that contains the asset catalog. Defaults to `.main`. | ||
| public init(name: String, bundle: Bundle = .main) { | ||
| self.name = name | ||
| self.bundle = bundle | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
CatalogAssetshows "Asset not found" in debug viewconfigureCatalogAssetloads asset data exclusively viaNSDataAsset, butNSDataAssetonly resolves Data Set entries — it returnsnilfor Image Sets. The scheme handler inLocalFileSchemeHandler.load(resource:key:)triesUIImage(named:in:compatibleWith:)first, so an Image Set CatalogAsset is served successfully in the webview, but the debug preview shows "Asset not found" becauseNSDataAssetfinds nothing. The fix is to mirror the scheme handler's resolution order: tryUIImage(named:)first, and only then fall back toNSDataAsset.Prompt To Fix With AI