From 31ce7378c96155c46531dedc20afd46f32de65ca Mon Sep 17 00:00:00 2001 From: David Jennes Date: Tue, 6 Jun 2017 03:46:45 +0200 Subject: [PATCH] Documentation changes + changelog --- CHANGELOG.md | 3 +++ Documentation/MigrationGuide.md | 4 ++-- Documentation/storyboards/swift2.md | 27 +++++++-------------------- Documentation/storyboards/swift3.md | 27 +++++++-------------------- templates/storyboards/swift2.stencil | 4 +++- templates/storyboards/swift3.stencil | 4 +++- 6 files changed, 25 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f162755..03b8878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ * Since Swift 2 is no longer actively supported, we now consider those templates as "legacy" and cannot guarantee that there won't be issues with the generated code. [David Jennes](https://github.com/djbe) [#53](https://github.com/SwiftGen/templates/issues/53) +* The iOS and macOS storyboard templates have been unified into one. The generated code also no longer uses enum cases for scenes but instead uses a generic struct. See the documentation for some examples. + [David Jennes](https://github.com/djbe) + [#57](https://github.com/SwiftGen/templates/issues/57) ### New Features diff --git a/Documentation/MigrationGuide.md b/Documentation/MigrationGuide.md index 9a41f20..0a69592 100644 --- a/Documentation/MigrationGuide.md +++ b/Documentation/MigrationGuide.md @@ -36,9 +36,9 @@ Below is a list of renamed and removed templates, grouped by subcommand. If your | --- | --- | ------ | | default | swift2 | | | lowercase | **deleted** | No longer needed since we prefix classes with their module | -| osx-default | macOS-swift2 | | +| osx-default | **deleted** | Unified with the iOS template, just use `swift2` | | osx-lowercase | **deleted** | No longer needed since we prefix classes with their module | -| osx-swift3 | macOS-swift3 | | +| osx-swift3 | **deleted** | Unified with the iOS template, just use `swift3` | | uppercase | **deleted** | No longer needed since we prefix classes with their module | ### Strings ### diff --git a/Documentation/storyboards/swift2.md b/Documentation/storyboards/swift2.md index 1546244..768e96a 100644 --- a/Documentation/storyboards/swift2.md +++ b/Documentation/storyboards/swift2.md @@ -29,29 +29,19 @@ Note: the generated code may look differently depending on the platform the stor ```swift enum StoryboardScene { - enum Dependency: String, StoryboardSceneType { + enum Dependency: StoryboardType { static let storyboardName = "Dependency" - case DependentScene = "Dependent" - static func instantiateDependent() -> UIViewController { - return StoryboardScene.Dependency.DependentScene.viewController() - } + static let Dependent = SceneType(Dependency.self, identifier: "Dependent") } - enum Message: String, StoryboardSceneType { + enum Message: StoryboardType { static let storyboardName = "Message" - case MessagesListScene = "MessagesList" - static func instantiateMessagesList() -> UITableViewController { - guard let vc = StoryboardScene.Message.MessagesListScene.viewController() as? UITableViewController - else { - fatalError("ViewController 'MessagesList' is not of the expected class UITableViewController.") - } - return vc - } + static let MessagesList = SceneType(Message.self, identifier: "MessagesList") } } enum StoryboardSegue { - enum Message: String, StoryboardSegueType { + enum Message: String, SegueType { case Embed case NonCustom } @@ -63,11 +53,8 @@ enum StoryboardSegue { ## Usage example ```swift -// You can instantiate scenes using the generic `viewController()` method: -let vc = StoryboardScene.Dependency.DependentScene.viewController() - -// or the `instantiate...()` method (which will cast to the correct type): -let vc2 = StoryboardScene.Message.instantiateMessagesList() +// You can instantiate scenes using the `controller` property: +let vc = StoryboardScene.Dependency.Dependent.controller // You can perform segues using: vc.performSegue(StoryboardSegue.Message.Embed) diff --git a/Documentation/storyboards/swift3.md b/Documentation/storyboards/swift3.md index a99a940..fa60ace 100644 --- a/Documentation/storyboards/swift3.md +++ b/Documentation/storyboards/swift3.md @@ -28,29 +28,19 @@ Note: the generated code may look differently depending on the platform the stor ```swift enum StoryboardScene { - enum Dependency: String, StoryboardSceneType { + enum Dependency: StoryboardType { static let storyboardName = "Dependency" - case dependentScene = "Dependent" - static func instantiateDependent() -> UIViewController { - return StoryboardScene.Dependency.dependentScene.viewController() - } + static let dependent = SceneType(storyboard: Dependency.self, identifier: "Dependent") } - enum Message: String, StoryboardSceneType { + enum Message: StoryboardType { static let storyboardName = "Message" - case messagesListScene = "MessagesList" - static func instantiateMessagesList() -> UITableViewController { - guard let vc = StoryboardScene.Message.messagesListScene.viewController() as? UITableViewController - else { - fatalError("ViewController 'MessagesList' is not of the expected class UITableViewController.") - } - return vc - } + static let messagesList = SceneType(storyboard: Message.self, identifier: "MessagesList") } } enum StoryboardSegue { - enum Message: String, StoryboardSegueType { + enum Message: String, SegueType { case embed case nonCustom } @@ -62,11 +52,8 @@ enum StoryboardSegue { ## Usage example ```swift -// You can instantiate scenes using the generic `viewController()` method: -let vc = StoryboardScene.Dependency.dependentScene.viewController() - -// or the `instantiate...()` method (which will cast to the correct type): -let vc2 = StoryboardScene.Message.instantiateMessagesList() +// You can instantiate scenes using the `controller` property: +let vc = StoryboardScene.Dependency.dependent.controller // You can perform segues using: vc.perform(segue: StoryboardSegue.Message.embed) diff --git a/templates/storyboards/swift2.stencil b/templates/storyboards/swift2.stencil index 1813735..328ce8f 100644 --- a/templates/storyboards/swift2.stencil +++ b/templates/storyboards/swift2.stencil @@ -1,6 +1,6 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen -{% if storyboards %} +{% if platform and storyboards %} {% set isAppKit %}{% if platform == "macOS" %}true{% endif %}{% endset %} {% set prefix %}{% if isAppKit %}NS{% else %}UI{% endif %}{% endset %} {% set controller %}{% if isAppKit %}Controller{% else %}ViewController{% endif %}{% endset %} @@ -99,6 +99,8 @@ enum {{param.segueEnumName|default:"StoryboardSegue"}} { // swiftlint:enable explicit_type_interface identifier_name line_length type_body_length type_name private final class BundleToken {} +{% elif storyboards %} +// Mixed AppKit and UIKit storyboard files found, please invoke swiftgen with these separately {% else %} // No storyboard found {% endif %} diff --git a/templates/storyboards/swift3.stencil b/templates/storyboards/swift3.stencil index b8e2bbb..6288d7f 100644 --- a/templates/storyboards/swift3.stencil +++ b/templates/storyboards/swift3.stencil @@ -1,6 +1,6 @@ // Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen -{% if storyboards %} +{% if platform and storyboards %} {% set isAppKit %}{% if platform == "macOS" %}true{% endif %}{% endset %} {% set prefix %}{% if isAppKit %}NS{% else %}UI{% endif %}{% endset %} {% set controller %}{% if isAppKit %}Controller{% else %}ViewController{% endif %}{% endset %} @@ -99,6 +99,8 @@ enum {{param.segueEnumName|default:"StoryboardSegue"}} { // swiftlint:enable explicit_type_interface identifier_name line_length type_body_length type_name private final class BundleToken {} +{% elif storyboards %} +// Mixed AppKit and UIKit storyboard files found, please invoke swiftgen with these separately {% else %} // No storyboard found {% endif %}