Skip to content

Commit 0c9dfff

Browse files
committed
Add UIStoryboard Extension
1 parent 513f957 commit 0c9dfff

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

samples/swift/uidemo/AppDelegate.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ import FirebaseAuthUI
2020

2121
@UIApplicationMain
2222
class AppDelegate: UIResponder, UIApplicationDelegate {
23-
24-
static var mainStoryboard: UIStoryboard {
25-
return UIStoryboard(name: "Main", bundle: nil)
26-
}
2723

2824
var window: UIWindow?
2925

samples/swift/uidemo/AuthViewController.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,5 @@ class AuthViewController: UIViewController {
118118
override func viewWillLayoutSubviews() {
119119
self.topConstraint.constant = self.topLayoutGuide.length
120120
}
121-
122-
static func fromStoryboard(storyboard: UIStoryboard = AppDelegate.mainStoryboard) -> AuthViewController {
123-
return storyboard.instantiateViewControllerWithIdentifier("AuthViewController") as! AuthViewController
124-
}
121+
125122
}

samples/swift/uidemo/ChatViewController.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,7 @@ class ChatViewController: UIViewController, UICollectionViewDelegateFlowLayout {
128128

129129
self.textView.text = ""
130130
}
131-
132-
// MARK: - Boilerplate
133-
134-
static func fromStoryboard(storyboard: UIStoryboard = AppDelegate.mainStoryboard) -> ChatViewController {
135-
return storyboard.instantiateViewControllerWithIdentifier("ChatViewController") as! ChatViewController
136-
}
137-
131+
138132
override func viewDidLoad() {
139133
super.viewDidLoad()
140134

samples/swift/uidemo/Sample.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ enum Sample: Int, RawRepresentable {
5252
func controller() -> UIViewController {
5353
switch self {
5454
case .Chat:
55-
return ChatViewController.fromStoryboard()
55+
return UIStoryboard.instantiateViewController("Main", identifier: "ChatViewController") as! ChatViewController
5656
case .Auth:
57-
return AuthViewController.fromStoryboard()
57+
return UIStoryboard.instantiateViewController("Main", identifier: "AuthViewController") as! AuthViewController
5858
}
5959
}
6060
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Copyright (c) 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
import UIKit
18+
19+
extension UIStoryboard {
20+
static func instantiateViewController(storyboard: String, identifier: String) -> UIViewController {
21+
return UIStoryboard(name: storyboard, bundle: nil).instantiateViewControllerWithIdentifier(identifier)
22+
}
23+
}

0 commit comments

Comments
 (0)