Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit d09639b

Browse files
committed
Changes for non-static storyboards
And also doc updates
1 parent 1b53677 commit d09639b

8 files changed

+125
-12
lines changed

Library/Core/FileResource.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88

99
import Foundation
1010

11-
public protocol FileResource {
11+
public struct FileResource {
1212
/// Bundle this file is in or nil for main bundle
13-
var bundle: NSBundle? { get }
13+
public let bundle: NSBundle?
1414

1515
/// Name of the file file on disk
16-
var name: String { get }
16+
public let name: String
1717

1818
/// Extension of the file on disk
19-
var pathExtension: String { get }
20-
}
19+
public let pathExtension: String
2120

22-
public extension FileResource {
2321
public var url: NSURL? {
2422
return bundle?.URLForResource(name, withExtension: pathExtension, subdirectory: nil, localization: nil)
2523
}
24+
25+
public init(bundle: NSBundle?, name: String, pathExtension: String) {
26+
self.bundle = bundle
27+
self.name = name
28+
self.pathExtension = pathExtension
29+
}
2630
}

Library/Core/FontResource.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
import Foundation
1010

11-
public protocol FontResource {
11+
public struct FontResource {
1212
/// Name of the font
13-
var fontName: String { get }
13+
let fontName: String
14+
15+
public init(fontName: String) {
16+
self.fontName = fontName
17+
}
1418
}

Library/Core/StoryboardResource.swift

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// StoryboardResource.swift
3+
// R.swift.Library
4+
//
5+
// Created by Mathijs Kadijk on 07-01-16.
6+
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
public protocol StoryboardResource {
13+
14+
/// Bundle this storyboard is in or nil for main bundle
15+
var bundle: NSBundle? { get }
16+
17+
/// Name of the storyboard file on disk
18+
var name: String { get }
19+
}
20+
21+
public protocol StoryboardResourceWithInitialController: StoryboardResource {
22+
23+
/// Type of the inital controller
24+
typealias InitialController
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// StoryboardResourceWithInitialController+UIKit.swift
3+
// R.swift.Library
4+
//
5+
// Created by Mathijs Kadijk on 07-01-16.
6+
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public extension StoryboardResourceWithInitialController {
12+
/**
13+
Instantiates and returns the initial view controller in the view controller graph.
14+
15+
- returns: The initial view controller in the storyboard.
16+
*/
17+
public func initialViewController() -> InitialController? {
18+
return UIStoryboard(resource: self).instantiateInitialViewController() as? InitialController
19+
}
20+
}

Library/UIKit/UIFont+FontResource.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import Foundation
1010

1111
public extension UIFont {
1212
/**
13-
Creates and returns a font object for the specified font resource and size.
13+
Creates and returns a font object for the specified font resource (R.font.*) and size.
1414

15-
- parameter font: The font resource for the specific font to load
15+
- parameter resource: The font resource (R.font.*) for the specific font to load
1616
- parameter size: The size (in points) to which the font is scaled. This value must be greater than 0.0.
1717

1818
- returns: A font object of the specified font resource and size.
1919
*/
20-
public convenience init?(font: FontResource, size: CGFloat) {
21-
self.init(name: font.fontName, size: size)
20+
public convenience init?(resource: FontResource, size: CGFloat) {
21+
self.init(name: resource.fontName, size: size)
2222
}
2323
}

Library/UIKit/UINib+NibResource.swift

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// UINib+NibResource.swift
3+
// R.swift.Library
4+
//
5+
// Created by Mathijs Kadijk on 08-01-16.
6+
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UINib {
12+
/**
13+
Returns a UINib object initialized to the nib file of the specified resource (R.nib.*).
14+
15+
- parameter resource: The resource (R.nib.*) to load
16+
17+
- returns: The initialized UINib object. An exception is thrown if there were errors during initialization or the nib file could not be located.
18+
*/
19+
convenience init(resource: NibResource) {
20+
self.init(nibName: resource.name, bundle: resource.bundle)
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// UIStoryboard+StoryboardResource.swift
3+
// R.swift.Library
4+
//
5+
// Created by Mathijs Kadijk on 07-01-16.
6+
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public extension UIStoryboard {
12+
/**
13+
Creates and returns a storyboard object for the specified storyboard resource (R.storyboard.*) file.
14+
15+
- parameter resource: The storyboard resource (R.storyboard.*) for the specific storyboard to load
16+
17+
- returns: A storyboard object for the specified file. If no storyboard resource file matching name exists, an exception is thrown with description: `Could not find a storyboard named 'XXXXXX' in bundle....`
18+
*/
19+
public convenience init(resource: StoryboardResource) {
20+
self.init(name: resource.name, bundle: resource.bundle)
21+
}
22+
}

R.swift.Library.xcodeproj/project.pbxproj

+16
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
D543F9CA1C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D543F9C91C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift */; };
1919
D543F9CC1C1499AB00D16A0C /* UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D543F9CB1C1499AB00D16A0C /* UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift */; };
2020
D543F9CF1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D543F9CE1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift */; };
21+
D5588CAB1C3F9DBE00912F97 /* UINib+NibResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5588CAA1C3F9DBE00912F97 /* UINib+NibResource.swift */; };
2122
D57E1EB31C3D762300DDA68F /* FontResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB21C3D762300DDA68F /* FontResource.swift */; };
2223
D57E1EB51C3D774000DDA68F /* UIFont+FontResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB41C3D774000DDA68F /* UIFont+FontResource.swift */; };
24+
D57E1EB71C3E482A00DDA68F /* StoryboardResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB61C3E482A00DDA68F /* StoryboardResource.swift */; };
25+
D57E1EB91C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB81C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift */; };
26+
D57E1EBB1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EBA1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift */; };
2327
D59246521C117A55007F94C7 /* Rswift.h in Headers */ = {isa = PBXBuildFile; fileRef = D59246511C117A55007F94C7 /* Rswift.h */; settings = {ATTRIBUTES = (Public, ); }; };
2428
D59246591C117A55007F94C7 /* Rswift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D592464E1C117A55007F94C7 /* Rswift.framework */; };
2529
D592465E1C117A55007F94C7 /* RswiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D592465D1C117A55007F94C7 /* RswiftTests.swift */; };
@@ -49,8 +53,12 @@
4953
D543F9C91C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+StoryboardSegueIdentifierProtocol.swift"; sourceTree = "<group>"; };
5054
D543F9CB1C1499AB00D16A0C /* UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift"; sourceTree = "<group>"; };
5155
D543F9CE1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TypedStoryboardSegueInfo+UIStoryboardSegue.swift"; sourceTree = "<group>"; };
56+
D5588CAA1C3F9DBE00912F97 /* UINib+NibResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINib+NibResource.swift"; sourceTree = "<group>"; };
5257
D57E1EB21C3D762300DDA68F /* FontResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FontResource.swift; sourceTree = "<group>"; };
5358
D57E1EB41C3D774000DDA68F /* UIFont+FontResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIFont+FontResource.swift"; sourceTree = "<group>"; };
59+
D57E1EB61C3E482A00DDA68F /* StoryboardResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardResource.swift; sourceTree = "<group>"; };
60+
D57E1EB81C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StoryboardResourceWithInitialController+UIKit.swift"; sourceTree = "<group>"; };
61+
D57E1EBA1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboard+StoryboardResource.swift"; sourceTree = "<group>"; };
5462
D592464E1C117A55007F94C7 /* Rswift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Rswift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5563
D59246511C117A55007F94C7 /* Rswift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Rswift.h; sourceTree = "<group>"; };
5664
D59246531C117A55007F94C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -91,6 +99,9 @@
9199
D543F9CE1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift */,
92100
D5E435A81C3CFB460091090C /* NibResource+UIKit.swift */,
93101
D57E1EB41C3D774000DDA68F /* UIFont+FontResource.swift */,
102+
D57E1EB81C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift */,
103+
D57E1EBA1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift */,
104+
D5588CAA1C3F9DBE00912F97 /* UINib+NibResource.swift */,
94105
);
95106
path = UIKit;
96107
sourceTree = "<group>";
@@ -104,6 +115,7 @@
104115
D543F9C01C14984300D16A0C /* NibResource.swift */,
105116
D5E435AC1C3D00770091090C /* FileResource.swift */,
106117
D57E1EB21C3D762300DDA68F /* FontResource.swift */,
118+
D57E1EB61C3E482A00DDA68F /* StoryboardResource.swift */,
107119
D53F19231C229D7200AE2FAD /* Validatable.swift */,
108120
);
109121
path = Core;
@@ -259,10 +271,14 @@
259271
D543F9CA1C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift in Sources */,
260272
D5E435AD1C3D00770091090C /* FileResource.swift in Sources */,
261273
D543F9BB1C1497EB00D16A0C /* Identifier.swift in Sources */,
274+
D57E1EB71C3E482A00DDA68F /* StoryboardResource.swift in Sources */,
275+
D57E1EBB1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift in Sources */,
262276
D57E1EB31C3D762300DDA68F /* FontResource.swift in Sources */,
277+
D57E1EB91C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift in Sources */,
263278
D543F9BD1C14980600D16A0C /* ReuseIdentifierProtocol.swift in Sources */,
264279
D543F9C11C14984300D16A0C /* NibResource.swift in Sources */,
265280
D57E1EB51C3D774000DDA68F /* UIFont+FontResource.swift in Sources */,
281+
D5588CAB1C3F9DBE00912F97 /* UINib+NibResource.swift in Sources */,
266282
D543F9C61C14992000D16A0C /* UICollectionView+ReuseIdentifierProtocol.swift in Sources */,
267283
D543F9BF1C14983100D16A0C /* StoryboardSegueIdentifierProtocol.swift in Sources */,
268284
D543F9C81C14995800D16A0C /* UIViewController+NibResource.swift in Sources */,

0 commit comments

Comments
 (0)