Skip to content

Commit

Permalink
Added visionOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
shadone committed Feb 9, 2024
1 parent 46a6c90 commit dab11c5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ _None_
[John Szumski](https://github.com/jszumski)
[#1007](https://github.com/SwiftGen/SwiftGen/issues/1007)
[#1008](https://github.com/SwiftGen/SwiftGen/pull/1008)
* CLI: Added support for visionOS platform.
[Denis Dzyubenko](https://github.com/shadone)
[#1099](https://github.com/SwiftGen/SwiftGen/issues/1099)

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftGenCLI/templates/colors/swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#if os(macOS)
import AppKit.NSColor
{{accessModifier}} typealias {{colorAlias}} = NSColor
#elseif os(iOS) || os(tvOS) || os(watchOS)
#elseif os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
import UIKit.UIColor
{{accessModifier}} typealias {{colorAlias}} = UIColor
#endif
Expand Down
16 changes: 8 additions & 8 deletions Sources/SwiftGenCLI/templates/fonts/swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% set fontType %}{{param.fontTypeName|default:"FontConvertible"}}{% endset %}
#if os(macOS)
import AppKit.NSFont
#elseif os(iOS) || os(tvOS) || os(watchOS)
#elseif os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
import UIKit.UIFont
#endif
#if canImport(SwiftUI)
Expand Down Expand Up @@ -54,7 +54,7 @@

#if os(macOS)
{{accessModifier}} typealias Font = NSFont
#elseif os(iOS) || os(tvOS) || os(watchOS)
#elseif os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
{{accessModifier}} typealias Font = UIFont
#endif

Expand All @@ -66,17 +66,17 @@
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, macOS 10.15, *)
{{accessModifier}} func swiftUIFont(size: CGFloat) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, size: size)
}

@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
@available(iOS 14.0, tvOS 14.0, watchOS 7.0, visionOS 1, macOS 11.0, *)
{{accessModifier}} func swiftUIFont(fixedSize: CGFloat) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, fixedSize: fixedSize)
}

@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
@available(iOS 14.0, tvOS 14.0, watchOS 7.0, visionOS 1, macOS 11.0, *)
{{accessModifier}} func swiftUIFont(size: CGFloat, relativeTo textStyle: SwiftUI.Font.TextStyle) -> SwiftUI.Font {
return SwiftUI.Font.custom(self, size: size, relativeTo: textStyle)
}
Expand All @@ -89,7 +89,7 @@
}

fileprivate func registerIfNeeded() {
#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
if !UIFont.fontNames(forFamilyName: family).contains(name) {
register()
}
Expand Down Expand Up @@ -118,15 +118,15 @@
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, macOS 10.15, *)
{{accessModifier}} extension SwiftUI.Font {
static func custom(_ font: {{fontType}}, size: CGFloat) -> SwiftUI.Font {
font.registerIfNeeded()
return custom(font.name, size: size)
}
}

@available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *)
@available(iOS 14.0, tvOS 14.0, watchOS 7.0, visionOS 1, macOS 11.0, *)
{{accessModifier}} extension SwiftUI.Font {
static func custom(_ font: {{fontType}}, fixedSize: CGFloat) -> SwiftUI.Font {
font.registerIfNeeded()
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftGenCLI/templates/ib/scenes-swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import {{module}}
return storyboard.storyboard.instantiate{{controller}}(identifier: identifier, creator: block)
}
{% else %}
@available(iOS 13.0, tvOS 13.0, *)
@available(iOS 13.0, tvOS 13.0, visionOS 1, *)
{{accessModifier}} func instantiate(creator block: @escaping (NSCoder) -> T?) -> T {
return storyboard.storyboard.instantiate{{controller}}(identifier: identifier, creator: block)
}
Expand Down Expand Up @@ -129,7 +129,7 @@ import {{module}}
return controller
}
{% else %}
@available(iOS 13.0, tvOS 13.0, *)
@available(iOS 13.0, tvOS 13.0, visionOS 1, *)
{{accessModifier}} func instantiate(creator block: @escaping (NSCoder) -> T?) -> T {
guard let controller = storyboard.storyboard.instantiateInitial{{controller}}(creator: block) else {
fatalError("Storyboard \(storyboard.storyboardName) does not have an initial scene.")
Expand Down
56 changes: 28 additions & 28 deletions Sources/SwiftGenCLI/templates/xcassets/swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% set hasSymbol %}{% for catalog in catalogs %}{% call hasValuesBlock catalog.assets "symbol" %}{% endfor %}{% endset %}
#if os(macOS)
import AppKit
#elseif os(iOS)
#elseif os(iOS) || os(visionOS)
{% if hasARResourceGroup %}
import ARKit
{% endif %}
Expand Down Expand Up @@ -188,20 +188,20 @@

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

@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, visionOS 1, macOS 10.13, *)
{{accessModifier}} private(set) lazy var color: Color = {
guard let color = Color(asset: self) else {
fatalError("Unable to load color asset named \(name).")
}
return color
}()

#if os(iOS) || os(tvOS)
@available(iOS 11.0, tvOS 11.0, *)
#if os(iOS) || os(tvOS) || os(visionOS)
@available(iOS 11.0, tvOS 11.0, visionOS 1, *)
{{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 {
Expand All @@ -212,7 +212,7 @@
#endif

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, macOS 10.15, *)
{{accessModifier}} private(set) lazy var swiftUIColor: SwiftUI.Color = {
SwiftUI.Color(asset: self)
}()
Expand All @@ -224,10 +224,10 @@
}

{{accessModifier}} extension {{colorType}}.Color {
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, visionOS 1, macOS 10.13, *)
convenience init?(asset: {{colorType}}) {
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
self.init(named: asset.name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
self.init(named: NSColor.Name(asset.name), bundle: bundle)
Expand All @@ -238,7 +238,7 @@
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, macOS 10.15, *)
{{accessModifier}} extension SwiftUI.Color {
init(asset: {{colorType}}) {
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
Expand All @@ -252,7 +252,7 @@
{{accessModifier}} struct {{dataType}} {
{{accessModifier}} fileprivate(set) var name: String

@available(iOS 9.0, tvOS 9.0, watchOS 6.0, macOS 10.11, *)
@available(iOS 9.0, tvOS 9.0, watchOS 6.0, visionOS 1, macOS 10.11, *)
{{accessModifier}} var data: NSDataAsset {
guard let data = NSDataAsset(asset: self) else {
fatalError("Unable to load data asset named \(name).")
Expand All @@ -261,11 +261,11 @@
}
}

@available(iOS 9.0, tvOS 9.0, watchOS 6.0, macOS 10.11, *)
@available(iOS 9.0, tvOS 9.0, watchOS 6.0, visionOS 1, macOS 10.11, *)
{{accessModifier}} extension NSDataAsset {
convenience init?(asset: {{dataType}}) {
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
self.init(name: asset.name, bundle: bundle)
#elseif os(macOS)
self.init(name: NSDataAsset.Name(asset.name), bundle: bundle)
Expand All @@ -280,14 +280,14 @@

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

@available(iOS 8.0, tvOS 9.0, watchOS 2.0, macOS 10.7, *)
@available(iOS 8.0, tvOS 9.0, watchOS 2.0, visionOS 1, macOS 10.7, *)
{{accessModifier}} var image: Image {
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
let image = Image(named: name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
let name = NSImage.Name(self.name)
Expand All @@ -301,8 +301,8 @@
return result
}

#if os(iOS) || os(tvOS)
@available(iOS 8.0, tvOS 9.0, *)
#if os(iOS) || os(tvOS) || os(visionOS)
@available(iOS 8.0, tvOS 9.0, visionOS 1, *)
{{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 {
Expand All @@ -313,19 +313,19 @@
#endif

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, 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(iOS 8.0, tvOS 9.0, watchOS 2.0, visionOS 1, *)
@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)
#if os(iOS) || os(tvOS) || os(visionOS)
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
self.init(named: asset.name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
Expand All @@ -337,7 +337,7 @@
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, macOS 10.15, *)
{{accessModifier}} extension SwiftUI.Image {
init(asset: {{imageType}}) {
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
Expand All @@ -361,15 +361,15 @@
{{accessModifier}} struct {{symbolType}} {
{{accessModifier}} fileprivate(set) var name: String

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

@available(iOS 12.0, tvOS 12.0, watchOS 5.0, *)
@available(iOS 12.0, tvOS 12.0, watchOS 5.0, visionOS 1, *)
{{accessModifier}} var image: Image {
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
let image = Image(named: name, in: bundle, compatibleWith: nil)
#elseif os(watchOS)
let image = Image(named: name)
Expand All @@ -380,7 +380,7 @@
return result
}

@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, *)
{{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 {
Expand All @@ -391,15 +391,15 @@
#endif

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, 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, *)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, visionOS 1, macOS 10.15, *)
{{accessModifier}} extension SwiftUI.Image {
init(asset: {{symbolType}}) {
let bundle = {{param.bundle|default:"BundleToken.bundle"}}
Expand Down

0 comments on commit dab11c5

Please sign in to comment.