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

Commit

Permalink
Changes for non-static storyboards
Browse files Browse the repository at this point in the history
And also doc updates
  • Loading branch information
mac-cain13 committed Jan 9, 2016
1 parent 1b53677 commit d09639b
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 12 deletions.
16 changes: 10 additions & 6 deletions Library/Core/FileResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@

import Foundation

public protocol FileResource {
public struct FileResource {
/// Bundle this file is in or nil for main bundle
var bundle: NSBundle? { get }
public let bundle: NSBundle?

/// Name of the file file on disk
var name: String { get }
public let name: String

/// Extension of the file on disk
var pathExtension: String { get }
}
public let pathExtension: String

public extension FileResource {
public var url: NSURL? {
return bundle?.URLForResource(name, withExtension: pathExtension, subdirectory: nil, localization: nil)
}

public init(bundle: NSBundle?, name: String, pathExtension: String) {
self.bundle = bundle
self.name = name
self.pathExtension = pathExtension
}
}
8 changes: 6 additions & 2 deletions Library/Core/FontResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import Foundation

public protocol FontResource {
public struct FontResource {
/// Name of the font
var fontName: String { get }
let fontName: String

public init(fontName: String) {
self.fontName = fontName
}
}
25 changes: 25 additions & 0 deletions Library/Core/StoryboardResource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// StoryboardResource.swift
// R.swift.Library
//
// Created by Mathijs Kadijk on 07-01-16.
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
//

import Foundation
import UIKit

public protocol StoryboardResource {

/// Bundle this storyboard is in or nil for main bundle
var bundle: NSBundle? { get }

/// Name of the storyboard file on disk
var name: String { get }
}

public protocol StoryboardResourceWithInitialController: StoryboardResource {

/// Type of the inital controller
typealias InitialController
}
20 changes: 20 additions & 0 deletions Library/UIKit/StoryboardResourceWithInitialController+UIKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// StoryboardResourceWithInitialController+UIKit.swift
// R.swift.Library
//
// Created by Mathijs Kadijk on 07-01-16.
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
//

import Foundation

public extension StoryboardResourceWithInitialController {
/**
Instantiates and returns the initial view controller in the view controller graph.
- returns: The initial view controller in the storyboard.
*/
public func initialViewController() -> InitialController? {
return UIStoryboard(resource: self).instantiateInitialViewController() as? InitialController
}
}
8 changes: 4 additions & 4 deletions Library/UIKit/UIFont+FontResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import Foundation

public extension UIFont {
/**
Creates and returns a font object for the specified font resource and size.
Creates and returns a font object for the specified font resource (R.font.*) and size.
- parameter font: The font resource for the specific font to load
- parameter resource: The font resource (R.font.*) for the specific font to load
- parameter size: The size (in points) to which the font is scaled. This value must be greater than 0.0.
- returns: A font object of the specified font resource and size.
*/
public convenience init?(font: FontResource, size: CGFloat) {
self.init(name: font.fontName, size: size)
public convenience init?(resource: FontResource, size: CGFloat) {
self.init(name: resource.fontName, size: size)
}
}
22 changes: 22 additions & 0 deletions Library/UIKit/UINib+NibResource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// UINib+NibResource.swift
// R.swift.Library
//
// Created by Mathijs Kadijk on 08-01-16.
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
//

import UIKit

extension UINib {
/**
Returns a UINib object initialized to the nib file of the specified resource (R.nib.*).
- parameter resource: The resource (R.nib.*) to load
- returns: The initialized UINib object. An exception is thrown if there were errors during initialization or the nib file could not be located.
*/
convenience init(resource: NibResource) {
self.init(nibName: resource.name, bundle: resource.bundle)
}
}
22 changes: 22 additions & 0 deletions Library/UIKit/UIStoryboard+StoryboardResource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// UIStoryboard+StoryboardResource.swift
// R.swift.Library
//
// Created by Mathijs Kadijk on 07-01-16.
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
//

import UIKit

public extension UIStoryboard {
/**
Creates and returns a storyboard object for the specified storyboard resource (R.storyboard.*) file.
- parameter resource: The storyboard resource (R.storyboard.*) for the specific storyboard to load
- 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....`
*/
public convenience init(resource: StoryboardResource) {
self.init(name: resource.name, bundle: resource.bundle)
}
}
16 changes: 16 additions & 0 deletions R.swift.Library.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
D543F9CA1C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D543F9C91C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift */; };
D543F9CC1C1499AB00D16A0C /* UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D543F9CB1C1499AB00D16A0C /* UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift */; };
D543F9CF1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D543F9CE1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift */; };
D5588CAB1C3F9DBE00912F97 /* UINib+NibResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5588CAA1C3F9DBE00912F97 /* UINib+NibResource.swift */; };
D57E1EB31C3D762300DDA68F /* FontResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB21C3D762300DDA68F /* FontResource.swift */; };
D57E1EB51C3D774000DDA68F /* UIFont+FontResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB41C3D774000DDA68F /* UIFont+FontResource.swift */; };
D57E1EB71C3E482A00DDA68F /* StoryboardResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB61C3E482A00DDA68F /* StoryboardResource.swift */; };
D57E1EB91C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EB81C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift */; };
D57E1EBB1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57E1EBA1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift */; };
D59246521C117A55007F94C7 /* Rswift.h in Headers */ = {isa = PBXBuildFile; fileRef = D59246511C117A55007F94C7 /* Rswift.h */; settings = {ATTRIBUTES = (Public, ); }; };
D59246591C117A55007F94C7 /* Rswift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D592464E1C117A55007F94C7 /* Rswift.framework */; };
D592465E1C117A55007F94C7 /* RswiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D592465D1C117A55007F94C7 /* RswiftTests.swift */; };
Expand Down Expand Up @@ -49,8 +53,12 @@
D543F9C91C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+StoryboardSegueIdentifierProtocol.swift"; sourceTree = "<group>"; };
D543F9CB1C1499AB00D16A0C /* UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboardSegue+StoryboardSegueIdentifierProtocol.swift"; sourceTree = "<group>"; };
D543F9CE1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TypedStoryboardSegueInfo+UIStoryboardSegue.swift"; sourceTree = "<group>"; };
D5588CAA1C3F9DBE00912F97 /* UINib+NibResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINib+NibResource.swift"; sourceTree = "<group>"; };
D57E1EB21C3D762300DDA68F /* FontResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FontResource.swift; sourceTree = "<group>"; };
D57E1EB41C3D774000DDA68F /* UIFont+FontResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIFont+FontResource.swift"; sourceTree = "<group>"; };
D57E1EB61C3E482A00DDA68F /* StoryboardResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardResource.swift; sourceTree = "<group>"; };
D57E1EB81C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StoryboardResourceWithInitialController+UIKit.swift"; sourceTree = "<group>"; };
D57E1EBA1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboard+StoryboardResource.swift"; sourceTree = "<group>"; };
D592464E1C117A55007F94C7 /* Rswift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Rswift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D59246511C117A55007F94C7 /* Rswift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Rswift.h; sourceTree = "<group>"; };
D59246531C117A55007F94C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -91,6 +99,9 @@
D543F9CE1C149C0A00D16A0C /* TypedStoryboardSegueInfo+UIStoryboardSegue.swift */,
D5E435A81C3CFB460091090C /* NibResource+UIKit.swift */,
D57E1EB41C3D774000DDA68F /* UIFont+FontResource.swift */,
D57E1EB81C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift */,
D57E1EBA1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift */,
D5588CAA1C3F9DBE00912F97 /* UINib+NibResource.swift */,
);
path = UIKit;
sourceTree = "<group>";
Expand All @@ -104,6 +115,7 @@
D543F9C01C14984300D16A0C /* NibResource.swift */,
D5E435AC1C3D00770091090C /* FileResource.swift */,
D57E1EB21C3D762300DDA68F /* FontResource.swift */,
D57E1EB61C3E482A00DDA68F /* StoryboardResource.swift */,
D53F19231C229D7200AE2FAD /* Validatable.swift */,
);
path = Core;
Expand Down Expand Up @@ -259,10 +271,14 @@
D543F9CA1C14998800D16A0C /* UIViewController+StoryboardSegueIdentifierProtocol.swift in Sources */,
D5E435AD1C3D00770091090C /* FileResource.swift in Sources */,
D543F9BB1C1497EB00D16A0C /* Identifier.swift in Sources */,
D57E1EB71C3E482A00DDA68F /* StoryboardResource.swift in Sources */,
D57E1EBB1C3E4C4300DDA68F /* UIStoryboard+StoryboardResource.swift in Sources */,
D57E1EB31C3D762300DDA68F /* FontResource.swift in Sources */,
D57E1EB91C3E4C1A00DDA68F /* StoryboardResourceWithInitialController+UIKit.swift in Sources */,
D543F9BD1C14980600D16A0C /* ReuseIdentifierProtocol.swift in Sources */,
D543F9C11C14984300D16A0C /* NibResource.swift in Sources */,
D57E1EB51C3D774000DDA68F /* UIFont+FontResource.swift in Sources */,
D5588CAB1C3F9DBE00912F97 /* UINib+NibResource.swift in Sources */,
D543F9C61C14992000D16A0C /* UICollectionView+ReuseIdentifierProtocol.swift in Sources */,
D543F9BF1C14983100D16A0C /* StoryboardSegueIdentifierProtocol.swift in Sources */,
D543F9C81C14995800D16A0C /* UIViewController+NibResource.swift in Sources */,
Expand Down

0 comments on commit d09639b

Please sign in to comment.