diff --git a/Tests/Expected/Colors/literals-swift3-context-defaults-customname.swift b/Tests/Expected/Colors/literals-swift3-context-defaults-customname.swift index ef2f48b..161aba2 100644 --- a/Tests/Expected/Colors/literals-swift3-context-defaults-customname.swift +++ b/Tests/Expected/Colors/literals-swift3-context-defaults-customname.swift @@ -1,12 +1,10 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit enum UIColor { } #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit #endif // swiftlint:disable file_length diff --git a/Tests/Expected/Colors/literals-swift3-context-defaults.swift b/Tests/Expected/Colors/literals-swift3-context-defaults.swift index 59b7215..37affcd 100644 --- a/Tests/Expected/Colors/literals-swift3-context-defaults.swift +++ b/Tests/Expected/Colors/literals-swift3-context-defaults.swift @@ -1,12 +1,10 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit enum ColorName { } #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit enum ColorName { } #endif diff --git a/Tests/Expected/Colors/literals-swift3-context-multiple.swift b/Tests/Expected/Colors/literals-swift3-context-multiple.swift index 43b8715..f959c21 100644 --- a/Tests/Expected/Colors/literals-swift3-context-multiple.swift +++ b/Tests/Expected/Colors/literals-swift3-context-multiple.swift @@ -1,12 +1,10 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit enum ColorName { } #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit enum ColorName { } #endif diff --git a/Tests/Expected/Colors/literals-swift4-context-defaults-customname.swift b/Tests/Expected/Colors/literals-swift4-context-defaults-customname.swift index ef2f48b..161aba2 100644 --- a/Tests/Expected/Colors/literals-swift4-context-defaults-customname.swift +++ b/Tests/Expected/Colors/literals-swift4-context-defaults-customname.swift @@ -1,12 +1,10 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit enum UIColor { } #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit #endif // swiftlint:disable file_length diff --git a/Tests/Expected/Colors/literals-swift4-context-defaults.swift b/Tests/Expected/Colors/literals-swift4-context-defaults.swift index 59b7215..37affcd 100644 --- a/Tests/Expected/Colors/literals-swift4-context-defaults.swift +++ b/Tests/Expected/Colors/literals-swift4-context-defaults.swift @@ -1,12 +1,10 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit enum ColorName { } #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit enum ColorName { } #endif diff --git a/Tests/Expected/Colors/literals-swift4-context-multiple.swift b/Tests/Expected/Colors/literals-swift4-context-multiple.swift index 43b8715..f959c21 100644 --- a/Tests/Expected/Colors/literals-swift4-context-multiple.swift +++ b/Tests/Expected/Colors/literals-swift4-context-multiple.swift @@ -1,12 +1,10 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit enum ColorName { } #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit enum ColorName { } #endif diff --git a/Tests/Expected/XCAssets/swift2-context-all-customname.swift b/Tests/Expected/XCAssets/swift2-context-all-customname.swift index 71bde36..940b73e 100644 --- a/Tests/Expected/XCAssets/swift2-context-all-customname.swift +++ b/Tests/Expected/XCAssets/swift2-context-all-customname.swift @@ -2,11 +2,9 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor typealias Image = UIImage #endif diff --git a/Tests/Expected/XCAssets/swift2-context-all-no-all-values.swift b/Tests/Expected/XCAssets/swift2-context-all-no-all-values.swift index d850e45..7ef5cab 100644 --- a/Tests/Expected/XCAssets/swift2-context-all-no-all-values.swift +++ b/Tests/Expected/XCAssets/swift2-context-all-no-all-values.swift @@ -2,11 +2,9 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor typealias Image = UIImage #endif diff --git a/Tests/Expected/XCAssets/swift2-context-all.swift b/Tests/Expected/XCAssets/swift2-context-all.swift index 358fe92..7f88cd7 100644 --- a/Tests/Expected/XCAssets/swift2-context-all.swift +++ b/Tests/Expected/XCAssets/swift2-context-all.swift @@ -2,11 +2,9 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor typealias Image = UIImage #endif diff --git a/Tests/Expected/XCAssets/swift3-context-all-customname.swift b/Tests/Expected/XCAssets/swift3-context-all-customname.swift index a9fb5c2..62f9bc5 100644 --- a/Tests/Expected/XCAssets/swift3-context-all-customname.swift +++ b/Tests/Expected/XCAssets/swift3-context-all-customname.swift @@ -2,11 +2,11 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor + typealias AssetColorTypeAlias = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor + typealias AssetColorTypeAlias = UIColor typealias Image = UIImage #endif @@ -37,8 +37,8 @@ struct XCTColorAsset { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: AssetColorTypeAlias { + return AssetColorTypeAlias(asset: self) } #endif } @@ -120,7 +120,7 @@ extension Image { } } -extension Color { +extension AssetColorTypeAlias { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: XCTColorAsset) { diff --git a/Tests/Expected/XCAssets/swift3-context-all-no-all-values.swift b/Tests/Expected/XCAssets/swift3-context-all-no-all-values.swift index b79f013..8260dc6 100644 --- a/Tests/Expected/XCAssets/swift3-context-all-no-all-values.swift +++ b/Tests/Expected/XCAssets/swift3-context-all-no-all-values.swift @@ -2,11 +2,11 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor + typealias AssetColorTypeAlias = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor + typealias AssetColorTypeAlias = UIColor typealias Image = UIImage #endif @@ -37,8 +37,8 @@ struct ColorAsset { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: AssetColorTypeAlias { + return AssetColorTypeAlias(asset: self) } #endif } @@ -90,7 +90,7 @@ extension Image { } } -extension Color { +extension AssetColorTypeAlias { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: ColorAsset) { diff --git a/Tests/Expected/XCAssets/swift3-context-all.swift b/Tests/Expected/XCAssets/swift3-context-all.swift index a367d17..12c01a7 100644 --- a/Tests/Expected/XCAssets/swift3-context-all.swift +++ b/Tests/Expected/XCAssets/swift3-context-all.swift @@ -2,11 +2,11 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor + typealias AssetColorTypeAlias = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor + typealias AssetColorTypeAlias = UIColor typealias Image = UIImage #endif @@ -37,8 +37,8 @@ struct ColorAsset { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: AssetColorTypeAlias { + return AssetColorTypeAlias(asset: self) } #endif } @@ -120,7 +120,7 @@ extension Image { } } -extension Color { +extension AssetColorTypeAlias { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: ColorAsset) { diff --git a/Tests/Expected/XCAssets/swift4-context-all-customname.swift b/Tests/Expected/XCAssets/swift4-context-all-customname.swift index 3034bc7..d2c6606 100644 --- a/Tests/Expected/XCAssets/swift4-context-all-customname.swift +++ b/Tests/Expected/XCAssets/swift4-context-all-customname.swift @@ -2,11 +2,11 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor + typealias AssetColorTypeAlias = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor + typealias AssetColorTypeAlias = UIColor typealias Image = UIImage #endif @@ -36,8 +36,8 @@ struct XCTColorAsset { fileprivate var name: String @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: AssetColorTypeAlias { + return AssetColorTypeAlias(asset: self) } } @@ -120,7 +120,7 @@ extension Image { } } -extension Color { +extension AssetColorTypeAlias { @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: XCTColorAsset) { let bundle = Bundle(for: BundleToken.self) diff --git a/Tests/Expected/XCAssets/swift4-context-all-no-all-values.swift b/Tests/Expected/XCAssets/swift4-context-all-no-all-values.swift index 855a004..698cb16 100644 --- a/Tests/Expected/XCAssets/swift4-context-all-no-all-values.swift +++ b/Tests/Expected/XCAssets/swift4-context-all-no-all-values.swift @@ -2,11 +2,11 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor + typealias AssetColorTypeAlias = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor + typealias AssetColorTypeAlias = UIColor typealias Image = UIImage #endif @@ -36,8 +36,8 @@ struct ColorAsset { fileprivate var name: String @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: AssetColorTypeAlias { + return AssetColorTypeAlias(asset: self) } } @@ -90,7 +90,7 @@ extension Image { } } -extension Color { +extension AssetColorTypeAlias { @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: ColorAsset) { let bundle = Bundle(for: BundleToken.self) diff --git a/Tests/Expected/XCAssets/swift4-context-all.swift b/Tests/Expected/XCAssets/swift4-context-all.swift index cc6c757..e77f4f6 100644 --- a/Tests/Expected/XCAssets/swift4-context-all.swift +++ b/Tests/Expected/XCAssets/swift4-context-all.swift @@ -2,11 +2,11 @@ #if os(OSX) import AppKit.NSImage - typealias Color = NSColor + typealias AssetColorTypeAlias = NSColor typealias Image = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor + typealias AssetColorTypeAlias = UIColor typealias Image = UIImage #endif @@ -36,8 +36,8 @@ struct ColorAsset { fileprivate var name: String @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: AssetColorTypeAlias { + return AssetColorTypeAlias(asset: self) } } @@ -120,7 +120,7 @@ extension Image { } } -extension Color { +extension AssetColorTypeAlias { @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: ColorAsset) { let bundle = Bundle(for: BundleToken.self) diff --git a/templates/colors/literals-swift3.stencil b/templates/colors/literals-swift3.stencil index 3e35229..d151d20 100644 --- a/templates/colors/literals-swift3.stencil +++ b/templates/colors/literals-swift3.stencil @@ -3,12 +3,10 @@ {% if palettes %} {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %} #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit {% if enumName != 'NSColor' %}enum {{enumName}} { }{% endif %} #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit {% if enumName != 'UIColor' %}enum {{enumName}} { }{% endif %} #endif diff --git a/templates/colors/literals-swift4.stencil b/templates/colors/literals-swift4.stencil index 3e35229..d151d20 100644 --- a/templates/colors/literals-swift4.stencil +++ b/templates/colors/literals-swift4.stencil @@ -3,12 +3,10 @@ {% if palettes %} {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %} #if os(OSX) - import AppKit.NSColor - typealias Color = NSColor + import AppKit {% if enumName != 'NSColor' %}enum {{enumName}} { }{% endif %} #elseif os(iOS) || os(tvOS) || os(watchOS) - import UIKit.UIColor - typealias Color = UIColor + import UIKit {% if enumName != 'UIColor' %}enum {{enumName}} { }{% endif %} #endif diff --git a/templates/colors/swift2.stencil b/templates/colors/swift2.stencil index 97d424c..2925952 100644 --- a/templates/colors/swift2.stencil +++ b/templates/colors/swift2.stencil @@ -1,18 +1,19 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen {% if palettes %} +{% set colorAlias %}{{param.colorAlias|default:"Color"}}{% endset %} #if os(OSX) import AppKit.NSColor - typealias Color = NSColor + typealias {{colorAlias}} = NSColor #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIColor - typealias Color = UIColor + typealias {{colorAlias}} = UIColor #endif // swiftlint:disable file_length // swiftlint:disable operator_usage_whitespace -extension Color { +extension {{colorAlias}} { convenience init(rgbaValue: UInt32) { let red = CGFloat((rgbaValue >> 24) & 0xff) / 255.0 let green = CGFloat((rgbaValue >> 16) & 0xff) / 255.0 @@ -28,7 +29,7 @@ extension Color { {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %} struct {{enumName}} { let rgbaValue: UInt32 - var color: Color { return Color(named: self) } + var color: {{colorAlias}} { return {{colorAlias}}(named: self) } {% macro rgbaValue color %}0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}{% endmacro %} {% macro enumBlock colors sp %} @@ -50,7 +51,7 @@ struct {{enumName}} { } // swiftlint:enable identifier_name line_length type_body_length -extension Color { +extension {{colorAlias}} { convenience init(named color: {{enumName}}) { self.init(rgbaValue: color.rgbaValue) } diff --git a/templates/colors/swift3.stencil b/templates/colors/swift3.stencil index 2a09016..56d933a 100644 --- a/templates/colors/swift3.stencil +++ b/templates/colors/swift3.stencil @@ -1,18 +1,19 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen {% if palettes %} +{% set colorAlias %}{{param.colorAlias|default:"Color"}}{% endset %} #if os(OSX) import AppKit.NSColor - typealias Color = NSColor + typealias {{colorAlias}} = NSColor #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIColor - typealias Color = UIColor + typealias {{colorAlias}} = UIColor #endif // swiftlint:disable file_length // swiftlint:disable operator_usage_whitespace -extension Color { +extension {{colorAlias}} { convenience init(rgbaValue: UInt32) { let red = CGFloat((rgbaValue >> 24) & 0xff) / 255.0 let green = CGFloat((rgbaValue >> 16) & 0xff) / 255.0 @@ -28,7 +29,7 @@ extension Color { {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %} struct {{enumName}} { let rgbaValue: UInt32 - var color: Color { return Color(named: self) } + var color: {{colorAlias}} { return {{colorAlias}}(named: self) } {% macro rgbaValue color %}0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}{% endmacro %} {% macro enumBlock colors sp %} @@ -50,7 +51,7 @@ struct {{enumName}} { } // swiftlint:enable identifier_name line_length type_body_length -extension Color { +extension {{colorAlias}} { convenience init(named color: {{enumName}}) { self.init(rgbaValue: color.rgbaValue) } diff --git a/templates/colors/swift4.stencil b/templates/colors/swift4.stencil index 2a09016..56d933a 100644 --- a/templates/colors/swift4.stencil +++ b/templates/colors/swift4.stencil @@ -1,18 +1,19 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen {% if palettes %} +{% set colorAlias %}{{param.colorAlias|default:"Color"}}{% endset %} #if os(OSX) import AppKit.NSColor - typealias Color = NSColor + typealias {{colorAlias}} = NSColor #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIColor - typealias Color = UIColor + typealias {{colorAlias}} = UIColor #endif // swiftlint:disable file_length // swiftlint:disable operator_usage_whitespace -extension Color { +extension {{colorAlias}} { convenience init(rgbaValue: UInt32) { let red = CGFloat((rgbaValue >> 24) & 0xff) / 255.0 let green = CGFloat((rgbaValue >> 16) & 0xff) / 255.0 @@ -28,7 +29,7 @@ extension Color { {% set enumName %}{{param.enumName|default:"ColorName"}}{% endset %} struct {{enumName}} { let rgbaValue: UInt32 - var color: Color { return Color(named: self) } + var color: {{colorAlias}} { return {{colorAlias}}(named: self) } {% macro rgbaValue color %}0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}{% endmacro %} {% macro enumBlock colors sp %} @@ -50,7 +51,7 @@ struct {{enumName}} { } // swiftlint:enable identifier_name line_length type_body_length -extension Color { +extension {{colorAlias}} { convenience init(named color: {{enumName}}) { self.init(rgbaValue: color.rgbaValue) } diff --git a/templates/xcassets/swift2.stencil b/templates/xcassets/swift2.stencil index 67a9771..f8e1bed 100644 --- a/templates/xcassets/swift2.stencil +++ b/templates/xcassets/swift2.stencil @@ -1,14 +1,13 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen {% if catalogs %} +{% set imageAlias %}{{param.imageAlias|default:"Image"}}{% endset %} #if os(OSX) import AppKit.NSImage - typealias Color = NSColor - typealias Image = NSImage + typealias {{imageAlias}} = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor - typealias Image = UIImage + typealias {{imageAlias}} = UIImage #endif // swiftlint:disable file_length @@ -21,14 +20,14 @@ typealias {{enumName}}Type = {{imageType}} struct {{imageType}} { private var name: String - var image: Image { + var image: {{imageAlias}} { let bundle = NSBundle(forClass: BundleToken.self) #if os(iOS) || os(tvOS) - let image = Image(named: name, inBundle: bundle, compatibleWithTraitCollection: nil) + let image = {{imageAlias}}(named: name, inBundle: bundle, compatibleWithTraitCollection: nil) #elseif os(OSX) let image = bundle.imageForResource(name) #elseif os(watchOS) - let image = Image(named: name) + let image = {{imageAlias}}(named: name) #endif guard let result = image else { fatalError("Unable to load image named \(name).") } return result @@ -96,7 +95,7 @@ enum {{enumName}} { } // swiftlint:enable identifier_name line_length nesting type_body_length type_name -extension Image { +extension {{imageAlias}} { @available(iOS 1.0, tvOS 1.0, watchOS 1.0, *) @available(OSX, deprecated, message: "This initializer is unsafe on macOS, please use the {{imageType}}.image property") diff --git a/templates/xcassets/swift3.stencil b/templates/xcassets/swift3.stencil index c8f01c4..be37a97 100644 --- a/templates/xcassets/swift3.stencil +++ b/templates/xcassets/swift3.stencil @@ -1,14 +1,16 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen {% if catalogs %} +{% set colorAlias %}{{param.colorAlias|default:"AssetColorTypeAlias"}}{% endset %} +{% set imageAlias %}{{param.imageAlias|default:"Image"}}{% endset %} #if os(OSX) import AppKit.NSImage - typealias Color = NSColor - typealias Image = NSImage + typealias {{colorAlias}} = NSColor + typealias {{imageAlias}} = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor - typealias Image = UIImage + typealias {{colorAlias}} = UIColor + typealias {{imageAlias}} = UIImage #endif // swiftlint:disable file_length @@ -21,14 +23,14 @@ typealias {{enumName}}Type = {{imageType}} struct {{imageType}} { fileprivate var name: String - var image: Image { + var image: {{imageAlias}} { let bundle = Bundle(for: BundleToken.self) #if os(iOS) || os(tvOS) - let image = Image(named: name, in: bundle, compatibleWith: nil) + let image = {{imageAlias}}(named: name, in: bundle, compatibleWith: nil) #elseif os(OSX) let image = bundle.image(forResource: name) #elseif os(watchOS) - let image = Image(named: name) + let image = {{imageAlias}}(named: name) #endif guard let result = image else { fatalError("Unable to load image named \(name).") } return result @@ -41,8 +43,8 @@ struct {{colorType}} { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: {{colorAlias}} { + return {{colorAlias}}(asset: self) } #endif } @@ -103,7 +105,7 @@ enum {{enumName}} { } // swiftlint:enable identifier_name line_length nesting type_body_length type_name -extension Image { +extension {{imageAlias}} { @available(iOS 1.0, tvOS 1.0, watchOS 1.0, *) @available(OSX, deprecated, message: "This initializer is unsafe on macOS, please use the {{imageType}}.image property") @@ -117,7 +119,7 @@ extension Image { } } -extension Color { +extension {{colorAlias}} { #if swift(>=3.2) @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: {{colorType}}) { diff --git a/templates/xcassets/swift4.stencil b/templates/xcassets/swift4.stencil index 79b2af0..f3308ff 100644 --- a/templates/xcassets/swift4.stencil +++ b/templates/xcassets/swift4.stencil @@ -1,14 +1,16 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen {% if catalogs %} +{% set colorAlias %}{{param.colorAlias|default:"AssetColorTypeAlias"}}{% endset %} +{% set imageAlias %}{{param.imageAlias|default:"Image"}}{% endset %} #if os(OSX) import AppKit.NSImage - typealias Color = NSColor - typealias Image = NSImage + typealias {{colorAlias}} = NSColor + typealias {{imageAlias}} = NSImage #elseif os(iOS) || os(tvOS) || os(watchOS) import UIKit.UIImage - typealias Color = UIColor - typealias Image = UIImage + typealias {{colorAlias}} = UIColor + typealias {{imageAlias}} = UIImage #endif // swiftlint:disable file_length @@ -21,14 +23,14 @@ typealias {{enumName}}Type = {{imageType}} struct {{imageType}} { fileprivate var name: String - var image: Image { + var image: {{imageAlias}} { let bundle = Bundle(for: BundleToken.self) #if os(iOS) || os(tvOS) - let image = Image(named: name, in: bundle, compatibleWith: nil) + let image = {{imageAlias}}(named: name, in: bundle, compatibleWith: nil) #elseif os(OSX) let image = bundle.image(forResource: NSImage.Name(name)) #elseif os(watchOS) - let image = Image(named: name) + let image = {{imageAlias}}(named: name) #endif guard let result = image else { fatalError("Unable to load image named \(name).") } return result @@ -40,8 +42,8 @@ struct {{colorType}} { fileprivate var name: String @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) - var color: Color { - return Color(asset: self) + var color: {{colorAlias}} { + return {{colorAlias}}(asset: self) } } {% macro enumBlock assets sp %} @@ -101,7 +103,7 @@ enum {{enumName}} { } // swiftlint:enable identifier_name line_length nesting type_body_length type_name -extension Image { +extension {{imageAlias}} { @available(iOS 1.0, tvOS 1.0, watchOS 1.0, *) @available(OSX, deprecated, message: "This initializer is unsafe on macOS, please use the {{imageType}}.image property") @@ -117,7 +119,7 @@ extension Image { } } -extension Color { +extension {{colorAlias}} { @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *) convenience init!(asset: {{colorType}}) { let bundle = Bundle(for: BundleToken.self)