You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Needed some help from @IanKeen to get it working, we got to this:
protocolAssetLoadable{associatedtypeAssetstaticfunc loadAsset(named name:String)->Asset}@propertyWrapperstructAssetCatalogEntry<T:AssetLoadable>where T ==T.Asset{letname:StringvarwrappedValue:T.Asset{T.loadAsset(named: name)}varprojectedValue:AssetCatalogEntry<T>{self}}extensionNSImage:AssetLoadable{staticfunc loadAsset(named name:String)->NSImage{
guard let result =Bundle.main.image(forResource: name)else{preconditionFailure("Unable to load image asset '\(name)'")}return result
}}extensionNSDataAsset:AssetLoadable{staticfunc loadAsset(named name:String)->NSDataAsset{
guard let result =NSDataAsset(name: name, bundle:.main)else{preconditionFailure("Unable to load data asset '\(name)'")}return result
}}enumAsset{@AssetCatalogEntry(name:"Foo")staticvarfoo:NSImage@AssetCatalogEntry(name:"Bar")staticvarbar:NSDataAsset}
Users can then access an asset directly using Asset.foo, and if they want other properties such as the name, they can still get it using Asset.$foo.name.
First question
Do we add a new swift5.1 template, or somehow add it to the existing swift5 templates based on swift version? It would be a breaking change for all users, so probably best to go with swift5.1?
Second question
To which parsers/templates do we add these?
Colors: swift5, not the literals template
Fonts: NO as a font still needs a size. We can use a closure as a wrappedValue, but it'd be (CGFloat) -> Font, where the parameter is unclear.
IB: maybe for storyboard scenes? Instead of using instantiate().
XCAssets: will need some tweaks for color caching and other perf. related things we do now in the template
Once we decide on these topics, I'll open a dedicated issue for each template to discuss the implementation, before creating a PR.
References #603 (inconvenient access to assets) and #605 (PR for that issue).
The text was updated successfully, but these errors were encountered:
Needed some help from @IanKeen to get it working, we got to this:
Users can then access an asset directly using
Asset.foo
, and if they want other properties such as the name, they can still get it usingAsset.$foo.name
.First question
Do we add a new
swift5.1
template, or somehow add it to the existing swift5 templates based on swift version? It would be a breaking change for all users, so probably best to go withswift5.1
?Second question
To which parsers/templates do we add these?
swift5
, not the literals templatewrappedValue
, but it'd be(CGFloat) -> Font
, where the parameter is unclear.instantiate()
.Once we decide on these topics, I'll open a dedicated issue for each template to discuss the implementation, before creating a PR.
References #603 (inconvenient access to assets) and #605 (PR for that issue).
The text was updated successfully, but these errors were encountered: