Skip to content
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

Added support the existential any to StoryboardType and CVarArg for Swift 5.6 or later. #1056

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ _None_
[#1007](https://github.com/SwiftGen/SwiftGen/issues/1007)
[#1008](https://github.com/SwiftGen/SwiftGen/pull/1008)

* Added support the existential `any` to `StoryboardType` and `CVarArg` for Swift 5.6 or later.
[treastrain / Tanaka Ryoga](https://github.com/treastrain)
[#1056](https://github.com/SwiftGen/SwiftGen/pull/1056)

### Bug Fixes

_None_
Expand Down
8 changes: 8 additions & 0 deletions Sources/SwiftGenCLI/templates/ib/scenes-swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ import {{module}}
}

{{accessModifier}} struct SceneType<T{% if not isAppKit %}: UIViewController{% endif %}> {
#if swift(>=5.6)
{{accessModifier}} let storyboard: any StoryboardType.Type
#else
{{accessModifier}} let storyboard: StoryboardType.Type
#endif
{{accessModifier}} let identifier: String

{{accessModifier}} func instantiate() -> T {
Expand Down Expand Up @@ -103,7 +107,11 @@ import {{module}}
}

{{accessModifier}} struct InitialSceneType<T{% if not isAppKit %}: UIViewController{% endif %}> {
#if swift(>=5.6)
{{accessModifier}} let storyboard: any StoryboardType.Type
#else
{{accessModifier}} let storyboard: StoryboardType.Type
#endif

{{accessModifier}} func instantiate() -> T {
guard let controller = storyboard.storyboard.instantiateInitial{{controller}}() as? T else {
Expand Down
11 changes: 11 additions & 0 deletions Sources/SwiftGenCLI/templates/strings/flat-swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ import Foundation
// MARK: - Implementation Details

extension {{enumName}} {
#if swift(>=5.6)
private static func tr(_ table: String, _ key: String, _ args: any CVarArg..., fallback value: String) -> String {
{% if param.lookupFunction %}
let format = {{ param.lookupFunction }}(key, table, value)
{% else %}
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: value, table: table)
{% endif %}
return String(format: format, locale: Locale.current, arguments: args)
}
#else
Comment on lines +74 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not creating a bit too much duplicated code to maintain here?

Cannot we just limit the #if to the func line?

Something more like this?

Suggested change
#if swift(>=5.6)
private static func tr(_ table: String, _ key: String, _ args: any CVarArg..., fallback value: String) -> String {
{% if param.lookupFunction %}
let format = {{ param.lookupFunction }}(key, table, value)
{% else %}
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: value, table: table)
{% endif %}
return String(format: format, locale: Locale.current, arguments: args)
}
#else
#if swift(>=5.6)
private static func tr(_ table: String, _ key: String, _ args: any CVarArg..., fallback value: String) -> String {
#else
private static func tr(_ table: String, _ key: String, _ args: CVarArg..., fallback value: String) -> String {
#endif

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you that there is some strain on its maintenance. However, such a syntax is invalid in Swift.

private static func tr(_ table: String, _ key: String, _ args: CVarArg..., fallback value: String) -> String {
{% if param.lookupFunction %}
let format = {{ param.lookupFunction }}(key, table, value)
Expand All @@ -79,6 +89,7 @@ extension {{enumName}} {
{% endif %}
return String(format: format, locale: Locale.current, arguments: args)
}
#endif
}
{% if not param.bundle and not param.lookupFunction %}

Expand Down
11 changes: 11 additions & 0 deletions Sources/SwiftGenCLI/templates/strings/structured-swift5.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ import Foundation
// MARK: - Implementation Details

extension {{enumName}} {
#if swift(>=5.6)
private static func tr(_ table: String, _ key: String, _ args: any CVarArg..., fallback value: String) -> String {
{% if param.lookupFunction %}
let format = {{ param.lookupFunction }}(key, table, value)
{% else %}
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: value, table: table)
{% endif %}
return String(format: format, locale: Locale.current, arguments: args)
}
#else
Comment on lines +78 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same #if scope question here.

Suggested change
#if swift(>=5.6)
private static func tr(_ table: String, _ key: String, _ args: any CVarArg..., fallback value: String) -> String {
{% if param.lookupFunction %}
let format = {{ param.lookupFunction }}(key, table, value)
{% else %}
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: value, table: table)
{% endif %}
return String(format: format, locale: Locale.current, arguments: args)
}
#else
#if swift(>=5.6)
private static func tr(_ table: String, _ key: String, _ args: any CVarArg..., fallback value: String) -> String {
#else
private static func tr(_ table: String, _ key: String, _ args: CVarArg..., fallback val
#endif

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static func tr(_ table: String, _ key: String, _ args: CVarArg..., fallback value: String) -> String {
{% if param.lookupFunction %}
let format = {{ param.lookupFunction }}(key, table, value)
Expand All @@ -83,6 +93,7 @@ extension {{enumName}} {
{% endif %}
return String(format: format, locale: Locale.current, arguments: args)
}
#endif
}
{% if not param.bundle and not param.lookupFunction %}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading