SwiftGen: SwiftGen Errors on Swift 6

SwiftGen has multiple errors with concurrency in Swift 6. Specifically, all of the Storyboard functions result in the following error: Call to main actor-isolated initializer 'init(name:bundle:)' in a synchronous nonisolated context.

In order to replicate Swift 6, you can turn on “Complete” strict concurrency checking in Build Settings and see the errors.

This will make SwiftGen unusable when Swift 6 is released. Please update SwiftGen to conform to the concurrency checks introduced in Swift 6.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 29
  • Comments: 15

Most upvoted comments

One option is to create your own stencil template for generating assets, like this one:

Potential Swift-6 Stencil template

// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen

{% if catalogs %}
{% macro hasValuesBlock assets filter %}
  {%- for asset in assets -%}
    {%- if asset.type == filter -%}
      1
    {%- elif asset.items -%}
      {% call hasValuesBlock asset.items filter %}
    {%- endif -%}
  {%- endfor -%}
{% endmacro %}
{% set enumName %}{{param.enumName|default:"Asset"}}{% endset %}
{% set arResourceGroupType %}{{param.arResourceGroupTypeName|default:"ARResourceGroupAsset"}}{% endset %}
{% set colorType %}{{param.colorTypeName|default:"ColorAsset"}}{% endset %}
{% set dataType %}{{param.dataTypeName|default:"DataAsset"}}{% endset %}
{% set imageType %}{{param.imageTypeName|default:"ImageAsset"}}{% endset %}
{% set symbolType %}{{param.symbolTypeName|default:"SymbolAsset"}}{% endset %}
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
{% set hasARResourceGroup %}{% for catalog in catalogs %}{% call hasValuesBlock catalog.assets "arresourcegroup" %}{% endfor %}{% endset %}
{% set hasColor %}{% for catalog in catalogs %}{% call hasValuesBlock catalog.assets "color" %}{% endfor %}{% endset %}
{% set hasData %}{% for catalog in catalogs %}{% call hasValuesBlock catalog.assets "data" %}{% endfor %}{% endset %}
{% set hasImage %}{% for catalog in catalogs %}{% call hasValuesBlock catalog.assets "image" %}{% endfor %}{% endset %}
{% set hasSymbol %}{% for catalog in catalogs %}{% call hasValuesBlock catalog.assets "symbol" %}{% endfor %}{% endset %}
#if os(macOS)
  import AppKit
#elseif os(iOS)
{% if hasARResourceGroup %}
  import ARKit
{% endif %}
  import UIKit
#elseif os(tvOS) || os(watchOS)
  import UIKit
#endif
#if canImport(SwiftUI)
  import SwiftUI
#endif

// Deprecated typealiases
{% if hasColor %}
@available(*, deprecated, renamed: "{{colorType}}.Color", message: "This typealias will be removed in SwiftGen 7.0")
{{accessModifier}} typealias {{param.colorAliasName|default:"AssetColorTypeAlias"}} = {{colorType}}.Color
{% endif %}
{% if hasImage %}
@available(*, deprecated, renamed: "{{imageType}}.Image", message: "This typealias will be removed in SwiftGen 7.0")
{{accessModifier}} typealias {{param.imageAliasName|default:"AssetImageTypeAlias"}} = {{imageType}}.Image
{% endif %}

// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Asset Catalogs

{% macro enumBlock assets %}
  {% call casesBlock assets %}
  {% if param.allValues %}

  // swiftlint:disable trailing_comma
  {% set hasItems %}{% call hasValuesBlock assets "arresourcegroup" %}{% endset %}
  {% if hasItems %}
  @available(*, deprecated, message: "All values properties are now deprecated")
  {{accessModifier}} static let allResourceGroups: [{{arResourceGroupType}}] = [
    {% filter indent:2," ",true %}{% call allValuesBlock assets "arresourcegroup" "" %}{% endfilter %}
  ]
  {% endif %}
  {% set hasItems %}{% call hasValuesBlock assets "color" %}{% endset %}
  {% if hasItems %}
  @available(*, deprecated, message: "All values properties are now deprecated")
  {{accessModifier}} static let allColors: [{{colorType}}] = [
    {% filter indent:2," ",true %}{% call allValuesBlock assets "color" "" %}{% endfilter %}
  ]
  {% endif %}
  {% set hasItems %}{% call hasValuesBlock assets "data" %}{% endset %}
  {% if hasItems %}
  @available(*, deprecated, message: "All values properties are now deprecated")
  {{accessModifier}} static let allDataAssets: [{{dataType}}] = [
    {% filter indent:2," ",true %}{% call allValuesBlock assets "data" "" %}{% endfilter %}
  ]
  {% endif %}
  {% set hasItems %}{% call hasValuesBlock assets "image" %}{% endset %}
  {% if hasItems %}
  @available(*, deprecated, message: "All values properties are now deprecated")
  {{accessModifier}} static let allImages: [{{imageType}}] = [
    {% filter indent:2," ",true %}{% call allValuesBlock assets "image" "" %}{% endfilter %}
  ]
  {% endif %}
  {% set hasItems %}{% call hasValuesBlock assets "symbol" %}{% endset %}
  {% if hasItems %}
  @available(*, deprecated, message: "All values properties are now deprecated")
  {{accessModifier}} static let allSymbols: [{{symbolType}}] = [
    {% filter indent:2," ",true %}{% call allValuesBlock assets "symbol" "" %}{% endfilter %}
  ]
  {% endif %}
  // swiftlint:enable trailing_comma
  {% endif %}
{% endmacro %}
{% macro casesBlock assets %}
  {% for asset in assets %}
  {% if asset.type == "arresourcegroup" %}
  {{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{arResourceGroupType}}(name: "{{asset.value}}")
  {% elif asset.type == "color" %}
  {{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}")
  {% elif asset.type == "data" %}
  {{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{dataType}}(name: "{{asset.value}}")
  {% elif asset.type == "image" %}
  {{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}")
  {% elif asset.type == "symbol" %}
  {{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{symbolType}}(name: "{{asset.value}}")
  {% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
  {{accessModifier}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
    {% filter indent:2," ",true %}{% call casesBlock asset.items %}{% endfilter %}
  }
  {% elif asset.items %}
  {% call casesBlock asset.items %}
  {% endif %}
  {% endfor %}
{% endmacro %}
{% macro allValuesBlock assets filter prefix %}
  {% for asset in assets %}
  {% if asset.type == filter %}
  {{prefix}}{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}},
  {% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
  {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}.{% endset %}
  {% call allValuesBlock asset.items filter prefix2 %}
  {% elif asset.items %}
  {% call allValuesBlock asset.items filter prefix %}
  {% endif %}
  {% endfor %}
{% endmacro %}
// swiftlint:disable identifier_name line_length nesting type_body_length type_name
{{accessModifier}} enum {{enumName}} {
  {% if catalogs.count > 1 or param.forceFileNameEnum %}
  {% for catalog in catalogs %}
  {{accessModifier}} enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
    {% if catalog.assets %}
    {% filter indent:2," ",true %}{% call enumBlock catalog.assets %}{% endfilter %}
    {% endif %}
  }
  {% endfor %}
  {% else %}
  {% call enumBlock catalogs.first.assets %}
  {% endif %}
}
// swiftlint:enable identifier_name line_length nesting type_body_length type_name

// MARK: - Implementation Details
{% if hasARResourceGroup %}

{{accessModifier}} struct {{arResourceGroupType}}: Sendable {
  {{accessModifier}} let name: String

  #if os(iOS)
  @available(iOS 11.3, *)
  {{accessModifier}} var referenceImages: Set<ARReferenceImage> {
    return ARReferenceImage.referenceImages(in: self)
  }

  @available(iOS 12.0, *)
  {{accessModifier}} var referenceObjects: Set<ARReferenceObject> {
    return ARReferenceObject.referenceObjects(in: self)
  }
  #endif
}

#if os(iOS)
@available(iOS 11.3, *)
{{accessModifier}} extension ARReferenceImage {
  static func referenceImages(in asset: {{arResourceGroupType}}) -> Set<ARReferenceImage> {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    return referenceImages(inGroupNamed: asset.name, bundle: bundle) ?? Set()
  }
}

@available(iOS 12.0, *)
{{accessModifier}} extension ARReferenceObject {
  static func referenceObjects(in asset: {{arResourceGroupType}}) -> Set<ARReferenceObject> {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    return referenceObjects(inGroupNamed: asset.name, bundle: bundle) ?? Set()
  }
}
#endif
{% endif %}
{% if hasColor %}

{{accessModifier}} final class {{colorType}}: Sendable {
  {{accessModifier}} let name: String

  #if os(macOS)
  {{accessModifier}} typealias Color = NSColor
  #elseif os(iOS) || os(tvOS) || os(watchOS)
  {{accessModifier}} typealias Color = UIColor
  #endif

  @available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
  {{accessModifier}} let color: Color

  #if os(iOS) || os(tvOS)
  @available(iOS 11.0, tvOS 11.0, *)
  {{accessModifier}} func color(compatibleWith traitCollection: UITraitCollection) -> Color {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    guard let color = Color(named: name, in: bundle, compatibleWith: traitCollection) else {
      fatalError("Unable to load color asset named \(name).")
    }
    return color
  }
  #endif

  #if canImport(SwiftUI)
  @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
  {{accessModifier}} var swiftUIColor: SwiftUI.Color {
    SwiftUI.Color(uiColor: color)
  }
  #endif

  fileprivate init(name: String) {
    self.name = name
    guard let color = Color(assetName: name) else {
      fatalError("Unable to load color asset named \(name).")
    }
    self.color = color
  }
}

{{accessModifier}} extension {{colorType}}.Color {
  @available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
  convenience init?(assetName: String) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    #if os(iOS) || os(tvOS)
    self.init(named: assetName, in: bundle, compatibleWith: nil)
    #elseif os(macOS)
    self.init(named: NSColor.Name(assetName), bundle: bundle)
    #elseif os(watchOS)
    self.init(named: assetName)
    #endif
  }
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
{{accessModifier}} extension SwiftUI.Color {
  init(assetName: String) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(assetName, bundle: bundle)
  }
}
#endif
{% endif %}
{% if hasData %}

{{accessModifier}} struct {{dataType}}: Sendable {
  {{accessModifier}} let name: String

  @available(iOS 9.0, tvOS 9.0, watchOS 6.0, macOS 10.11, *)
  {{accessModifier}} var data: NSDataAsset {
    guard let data = NSDataAsset(asset: self) else {
      fatalError("Unable to load data asset named \(name).")
    }
    return data
  }
}

@available(iOS 9.0, tvOS 9.0, watchOS 6.0, macOS 10.11, *)
{{accessModifier}} extension NSDataAsset {
  convenience init?(asset: {{dataType}}) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    #if os(iOS) || os(tvOS) || os(watchOS)
    self.init(name: asset.name, bundle: bundle)
    #elseif os(macOS)
    self.init(name: NSDataAsset.Name(asset.name), bundle: bundle)
    #endif
  }
}
{% endif %}
{% if hasImage %}

{{accessModifier}} struct {{imageType}}: Sendable {
  {{accessModifier}} let name: String

  #if os(macOS)
  {{accessModifier}} typealias Image = NSImage
  #elseif os(iOS) || os(tvOS) || os(watchOS)
  {{accessModifier}} typealias Image = UIImage
  #endif

  @available(iOS 8.0, tvOS 9.0, watchOS 2.0, macOS 10.7, *)
  {{accessModifier}} var image: Image {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    #if os(iOS) || os(tvOS)
    let image = Image(named: name, in: bundle, compatibleWith: nil)
    #elseif os(macOS)
    let name = NSImage.Name(self.name)
    let image = (bundle == .main) ? NSImage(named: name) : bundle.image(forResource: name)
    #elseif os(watchOS)
    let image = Image(named: name)
    #endif
    guard let result = image else {
      fatalError("Unable to load image asset named \(name).")
    }
    return result
  }

  #if os(iOS) || os(tvOS)
  @available(iOS 8.0, tvOS 9.0, *)
  {{accessModifier}} func image(compatibleWith traitCollection: UITraitCollection) -> Image {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    guard let result = Image(named: name, in: bundle, compatibleWith: traitCollection) else {
      fatalError("Unable to load image asset named \(name).")
    }
    return result
  }
  #endif

  #if canImport(SwiftUI)
  @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
  {{accessModifier}} var swiftUIImage: SwiftUI.Image {
    SwiftUI.Image(asset: self)
  }
  #endif
}

{{accessModifier}} extension {{imageType}}.Image {
  @available(iOS 8.0, tvOS 9.0, watchOS 2.0, *)
  @available(macOS, deprecated,
    message: "This initializer is unsafe on macOS, please use the {{imageType}}.image property")
  convenience init?(asset: {{imageType}}) {
    #if os(iOS) || os(tvOS)
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(named: asset.name, in: bundle, compatibleWith: nil)
    #elseif os(macOS)
    self.init(named: NSImage.Name(asset.name))
    #elseif os(watchOS)
    self.init(named: asset.name)
    #endif
  }
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
{{accessModifier}} extension SwiftUI.Image {
  init(asset: {{imageType}}) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(asset.name, bundle: bundle)
  }

  init(asset: {{imageType}}, label: Text) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(asset.name, bundle: bundle, label: label)
  }

  init(decorative asset: {{imageType}}) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(decorative: asset.name, bundle: bundle)
  }
}
#endif
{% endif %}
{% if hasSymbol %}

{{accessModifier}} struct {{symbolType}}: Sendable {
  {{accessModifier}} let name: String

  #if os(iOS) || os(tvOS) || os(watchOS)
  @available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
  {{accessModifier}} typealias Configuration = UIImage.SymbolConfiguration
  {{accessModifier}} typealias Image = UIImage

  @available(iOS 12.0, tvOS 12.0, watchOS 5.0, *)
  {{accessModifier}} var image: Image {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    #if os(iOS) || os(tvOS)
    let image = Image(named: name, in: bundle, compatibleWith: nil)
    #elseif os(watchOS)
    let image = Image(named: name)
    #endif
    guard let result = image else {
      fatalError("Unable to load symbol asset named \(name).")
    }
    return result
  }

  @available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
  {{accessModifier}} func image(with configuration: Configuration) -> Image {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    guard let result = Image(named: name, in: bundle, with: configuration) else {
      fatalError("Unable to load symbol asset named \(name).")
    }
    return result
  }
  #endif

  #if canImport(SwiftUI)
  @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
  {{accessModifier}} var swiftUIImage: SwiftUI.Image {
    SwiftUI.Image(asset: self)
  }
  #endif
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
{{accessModifier}} extension SwiftUI.Image {
  init(asset: {{symbolType}}) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(asset.name, bundle: bundle)
  }

  init(asset: {{symbolType}}, label: Text) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(asset.name, bundle: bundle, label: label)
  }

  init(decorative asset: {{symbolType}}) {
    let bundle = {{param.bundle|default:"BundleToken.bundle"}}
    self.init(decorative: asset.name, bundle: bundle)
  }
}
#endif
{% endif %}
{% if not param.bundle %}

// swiftlint:disable convenience_type
private final class BundleToken {
  static let bundle: Bundle = {
    #if SWIFT_PACKAGE
    return Bundle.module
    #else
    return Bundle(for: BundleToken.self)
    #endif
  }()
}
// swiftlint:enable convenience_type
{% endif %}
{% else %}
// No assets found
{% endif %}

This will change the generated Assets to look something like this:

Image

Since these will all be defined in an enum like so:

public enum Asset {
  static let myColor = ColorAsset(name: "...")
  static let myColor2 = ColorAsset(name: "...")
  // etc
}

the static lets are inherently lazy – and so using a let property should be the same as using a lazy var.

Hi it’s been almost year since that thread opened. Is there any plans for release with swift-6 support?

Can confirm generated Images and Sounds also have issues.

Static property 'exampleImage' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Hi, is there any progress? Cause Xcode 16 already released

The same is true for ColorAsset and ImageAsset within an Asset.

Static property 'exampleColor' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Any update on this?

If someone would be looking for quick solution for runtime-swift5 plist template, here is potential quick fix using @unchecked Sendable and var instead let:

// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen

{% if files %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
import Foundation

// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length

// MARK: - Plist Files
{% macro fileBlock file %}
  {% call documentBlock file file.document %}
{% endmacro %}
{% macro documentBlock file document %}
  {% set rootType %}{% call typeBlock document.metadata %}{% endset %}
  {% if document.metadata.type == "Array" %}
  {{accessModifier}} static let items: {{rootType}} = arrayFromPlist(at: "{% call transformPath file.path %}")
  {% elif document.metadata.type == "Dictionary" %}
  private static let _document = PlistDocument(path: "{% call transformPath file.path %}")
  {% for key,value in document.metadata.properties %}
  {{accessModifier}} {%+ call propertyBlock key value %}
  {% endfor %}
  {% else %}
  // Unsupported root type `{{rootType}}`
  {% endif %}
{% endmacro %}
{% macro typeBlock metadata %}
  {%- if metadata.type == "Array" -%}
    [{% call typeBlock metadata.element %}]
  {%- elif metadata.type == "Dictionary" -%}
    [String: Any]
  {%- else -%}
    {{metadata.type}}
  {%- endif -%}
{% endmacro %}
{% macro propertyBlock key metadata %}
  {%- set propertyName %}{{key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset -%}
  {%- set propertyType %}{% call typeBlock metadata %}{% endset -%}
  static var {{propertyName}}: {{propertyType}} { _document["{{key}}"] }
{% endmacro %}
{% macro transformPath path %}
  {%- if param.preservePath -%}
    {{path}}
  {%- else -%}
    {{path|basename}}
  {%- endif -%}
{% endmacro %}

// swiftlint:disable identifier_name line_length type_body_length
{{accessModifier}} enum {{param.enumName|default:"PlistFiles"}} {
  {% if files.count > 1 or param.forceFileNameEnum %}
  {% for file in files %}
  {{accessModifier}} enum {{file.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
    {% filter indent:2," ",true %}{% call fileBlock file %}{% endfilter %}
  }
  {% endfor %}
  {% else %}
  {% call fileBlock files.first %}
  {% endif %}
}
// swiftlint:enable identifier_name line_length type_body_length

// MARK: - Implementation Details

private func arrayFromPlist<T>(at path: String) -> [T] {
  {% if param.lookupFunction %}
  guard let url = {{param.lookupFunction}}(path),
  {% else %}
  guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
  {% endif %}
    let data = NSArray(contentsOf: url) as? [T] else {
    fatalError("Unable to load PLIST at path: \(path)")
  }
  return data
}

private struct PlistDocument: @unchecked Sendable {
  let data: [String: Any]

  init(path: String) {
    {% if param.lookupFunction %}
    guard let url = {{param.lookupFunction}}(path),
    {% else %}
    guard let url = {{param.bundle|default:"BundleToken.bundle"}}.url(forResource: path, withExtension: nil),
    {% endif %}
      let data = NSDictionary(contentsOf: url) as? [String: Any] else {
        fatalError("Unable to load PLIST at path: \(path)")
    }
    self.data = data
  }

  subscript<T>(key: String) -> T {
    guard let result = data[key] as? T else {
      fatalError("Property '\(key)' is not of type \(T.self)")
    }
    return result
  }
}
{% if not param.bundle and not param.lookupFunction %}

// swiftlint:disable convenience_type
private final class BundleToken {
  static let bundle: Bundle = {
    #if SWIFT_PACKAGE
    return Bundle.module
    #else
    return Bundle(for: BundleToken.self)
    #endif
  }()
}
// swiftlint:enable convenience_type
{% endif %}
{% else %}
// No files found
{% endif %}

I just simply changed enum to actor which conforms Sendable. Here is the stencil file of it.

// swiftlint:disable all
import SwiftUI
{% if catalogs %}
{% set enumName %}{{param.enumName|default:"Asset"}}{% endset %}
{% set colorType %}{{param.colorTypeName|default:"ColorAsset"}}{% endset %}
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
{% set accessModifier %}{% if param.internalAccess %}internal{% else %}public{% endif %}{% endset %}
{% macro enumBlock assets %}
  {% call casesBlock assets %}
  {% if param.allValues %}
  {{accessModifier}} static let allColors: [{{colorType}}] = [
    {% filter indent:2 %}{% call allValuesBlock assets "color" "" %}{% endfilter %}
  ]
  {{accessModifier}} static let allImages: [{{imageType}}] = [
    {% filter indent:2 %}{% call allValuesBlock assets "image" "" %}{% endfilter %}
  ]
  {% endif %}
{% endmacro %}
{% macro casesBlock assets %}
  {% for asset in assets %}
  {% if asset.type == "color" %}
  {{accessModifier}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}")
  {% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
  {{accessModifier}} actor {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {

    {% filter indent:2 %}{% call casesBlock asset.items %}{% endfilter %}
  }
  {% elif asset.items %}
  {% call casesBlock asset.items %}
  {% endif %}
  {% endfor %}
{% endmacro %}
{% macro allValuesBlock assets filter prefix %}
  {% for asset in assets %}
  {% if asset.type == filter %}
  {{prefix}}{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}},
  {% elif asset.items and ( forceNamespaces == "true" or asset.isNamespaced == "true" ) %}
  {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}.{% endset %}
  {% call allValuesBlock asset.items filter prefix2 %}
  {% elif asset.items %}
  {% call allValuesBlock asset.items filter prefix %}
  {% endif %}
  {% endfor %}
{% endmacro %}

{{accessModifier}} actor {{enumName}} {
  {% if catalogs.count > 1 %}
  {% for catalog in catalogs %}
  {{accessModifier}} actor {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
    {% filter indent:2 %}{% call enumBlock catalog.assets %}{% endfilter %}
  }
  {% endfor %}
  {% else %}
  {% call enumBlock catalogs.first.assets %}
  {% endif %}
}

{{accessModifier}} struct {{colorType}} {
  fileprivate let name: String

  {{accessModifier}} var color: Color {
    Color(self)
  }
}

{{accessModifier}} extension Color {
  init(_ asset: {{colorType}}) {
    self.init(asset.name, bundle: Bundle.module)
  }
}

{% else %}
// No assets found
{% endif %}
// swiftlint:enable all

There is another issue in Swift 6. Instead of generating:

private static func tr(…_ args: CVarArg...…) -> String { …

…it needs to be:

private static func tr(…_ args: any CVarArg...…) -> String { …

(adding any)

This should be backwards-compatible to Swift 5 and can easily be previewed with the ExistentialAny Swift feature flag. I wouldn’t mind opening a PR for the Swift 5 template, anything I should be aware of before doing that?

Oh, I may have missed that – happy to hear if anyone has a reference to that. Given it’s a very minor change in the template, it probably doesn’t hurt to add it, given it’s valid from Swift 5.6?