Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Unify the iOS and macOS storyboard templates #57

Merged
merged 5 commits into from
Jul 7, 2017
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Documentation/MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down
87 changes: 0 additions & 87 deletions Documentation/storyboards/macOS-swift2.md

This file was deleted.

86 changes: 0 additions & 86 deletions Documentation/storyboards/macOS-swift3.md

This file was deleted.

33 changes: 11 additions & 22 deletions Documentation/storyboards/swift2.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
## When to use it

- When you need to generate *Swift 2* code
- You want to generate code for UIKit platforms (iOS, tvOS and watchOS)
- **Warning**: Swift 2 is no longer actively supported, so we cannot guarantee that there won't be issues with the generated code.
- The generated code supports both UIKit platforms (iOS, tvOS and watchOS) and AppKit platform (macOS)
- **Warning**: Swift 2 is no longer actively supported, so we won't maintain this template and don't unit-test the generated code for it anymore.

## Customization

Expand All @@ -24,33 +24,25 @@ You can customize some elements of this template by overriding the following par

## Generated Code

Note: the generated code may look differently depending on the platform the storyboard file is targeting.

**Extract:**

```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<UIViewController>(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<UITableViewController>(Message.self, identifier: "MessagesList")
}
}
enum StoryboardSegue {
enum Message: String, StoryboardSegueType {
enum Message: String, SegueType {
case Embed
case NonCustom
}
Expand All @@ -62,11 +54,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)
Expand Down
31 changes: 10 additions & 21 deletions Documentation/storyboards/swift3.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## When to use it

- When you need to generate *Swift 3* code
- You want to generate code for UIKit platforms (iOS, tvOS and watchOS)
- The generated code supports both UIKit platforms (iOS, tvOS and watchOS) and AppKit platform (macOS)

## Customization

Expand All @@ -23,33 +23,25 @@ You can customize some elements of this template by overriding the following par

## Generated Code

Note: the generated code may look differently depending on the platform the storyboard file is targeting.

**Extract:**

```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<UIViewController>(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<UITableViewController>(storyboard: Message.self, identifier: "MessagesList")
}
}
enum StoryboardSegue {
enum Message: String, StoryboardSegueType {
enum Message: String, SegueType {
case embed
case nonCustom
}
Expand All @@ -61,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.perform(segue: StoryboardSegue.Message.embed)
Expand Down
Loading