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

Commit 1c69fbc

Browse files
authored
Merge pull request #17 from mac-cain13/swift3
Swift 3 + renames
2 parents 038468f + c922022 commit 1c69fbc

20 files changed

+124
-106
lines changed

Library/Core/FileResource.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
public protocol FileResourceType {
1212

1313
/// Bundle this file is in
14-
var bundle: NSBundle { get }
14+
var bundle: Bundle { get }
1515

1616
/// Name of the file file on disk
1717
var name: String { get }
@@ -23,7 +23,7 @@ public protocol FileResourceType {
2323
public extension FileResourceType {
2424
/// Name of the file on disk with the pathExtension
2525
var fullName: String {
26-
return [name, pathExtension].joinWithSeparator(".")
26+
return [name, pathExtension].joined(separator: ".")
2727
}
2828

2929
/**
@@ -32,30 +32,30 @@ public extension FileResourceType {
3232
- returns: The full pathname for this resource or nil if the file could not be located.
3333
*/
3434
func path() -> String? {
35-
return bundle.pathForResource(self)
35+
return bundle.path(forResource: self)
3636
}
3737

3838
/**
3939
Returns the file URL for this resource.
4040

4141
- returns: The file URL for this resource or nil if the file could not be located.
4242
*/
43-
func url() -> NSURL? {
44-
return bundle.URLForResource(self)
43+
func url() -> URL? {
44+
return bundle.url(forResource: self)
4545
}
4646
}
4747

4848
public struct FileResource: FileResourceType {
4949
/// Bundle this file is in
50-
public let bundle: NSBundle
50+
public let bundle: Bundle
5151

5252
/// Name of the file on disk, without the pathExtension
5353
public let name: String
5454

5555
/// Extension of the file on disk
5656
public let pathExtension: String
5757

58-
public init(bundle: NSBundle, name: String, pathExtension: String) {
58+
public init(bundle: Bundle, name: String, pathExtension: String) {
5959
self.bundle = bundle
6060
self.name = name
6161
self.pathExtension = pathExtension

Library/Core/ImageResource.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
public protocol ImageResourceType {
1212

1313
/// Bundle this image is in
14-
var bundle: NSBundle { get }
14+
var bundle: Bundle { get }
1515

1616
/// Name of the image
1717
var name: String { get }
@@ -20,12 +20,12 @@ public protocol ImageResourceType {
2020
public struct ImageResource: ImageResourceType {
2121

2222
/// Bundle this image is in
23-
public let bundle: NSBundle
23+
public let bundle: Bundle
2424

2525
/// Name of the image
2626
public let name: String
2727

28-
public init(bundle: NSBundle, name: String) {
28+
public init(bundle: Bundle, name: String) {
2929
self.bundle = bundle
3030
self.name = name
3131
}

Library/Core/NibResource.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
public protocol NibResourceType {
1313

1414
/// Bundle this nib is in or nil for main bundle
15-
var bundle: NSBundle { get }
15+
var bundle: Bundle { get }
1616

1717
/// Name of the nib file on disk
1818
var name: String { get }

Library/Core/StoryboardResource.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
public protocol StoryboardResourceType {
1212

1313
/// Bundle this storyboard is in
14-
var bundle: NSBundle { get }
14+
var bundle: Bundle { get }
1515

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

Library/Core/StoryboardSegueIdentifierProtocol.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ public struct StoryboardSegueIdentifier<Segue, Source, Destination>: StoryboardS
4444
}
4545

4646
/// Create a new StoryboardSegue based on the identifier and source view controller
47-
public func storyboardSegueWithSource(sourceViewController: Source)
47+
public func storyboardSegue(withSource source: Source)
4848
-> StoryboardSegue<Segue, Source, Destination>
4949
{
50-
return StoryboardSegue(identifier: self, sourceViewController: sourceViewController)
50+
return StoryboardSegue(identifier: self, source: source)
5151
}
5252
}
5353

@@ -63,7 +63,7 @@ public struct TypedStoryboardSegueInfo<Segue, Source, Destination>: StoryboardSe
6363
public typealias DestinationType = Destination
6464

6565
/// Segue destination view controller
66-
public let destinationViewController: Destination
66+
public let destination: Destination
6767

6868
/// Segue identifier
6969
public let identifier: String
@@ -72,7 +72,7 @@ public struct TypedStoryboardSegueInfo<Segue, Source, Destination>: StoryboardSe
7272
public let segue: Segue
7373

7474
/// Segue source view controller
75-
public let sourceViewController: Source
75+
public let source: Source
7676
}
7777

7878
/// Segue with identifier and source view controller
@@ -81,15 +81,15 @@ public struct StoryboardSegue<Segue, Source, Destination> {
8181
public let identifier: StoryboardSegueIdentifier<Segue, Source, Destination>
8282

8383
/// Segue source view controller
84-
public let sourceViewController: Source
84+
public let source: Source
8585

8686
/**
8787
Create a new segue based on the identifier and source view controller
8888

8989
- returns: A new StoryboardSegue
9090
*/
91-
public init(identifier: StoryboardSegueIdentifier<Segue, Source, Destination>, sourceViewController: Source) {
91+
public init(identifier: StoryboardSegueIdentifier<Segue, Source, Destination>, source: Source) {
9292
self.identifier = identifier
93-
self.sourceViewController = sourceViewController
93+
self.source = source
9494
}
9595
}

Library/Core/StoryboardViewControllerResource.swift

-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ public struct StoryboardViewControllerResource<ViewController>: StoryboardViewCo
2222
self.identifier = identifier
2323
}
2424
}
25-

Library/Core/StringResource.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public protocol StringResourceType {
1717
var tableName: String { get }
1818

1919
/// Bundle this string is in
20-
var bundle: NSBundle { get }
20+
var bundle: Bundle { get }
2121

2222
/// Locales of the a localizable string
2323
var locales: [String] { get }
@@ -35,15 +35,15 @@ public struct StringResource: StringResourceType {
3535
public let tableName: String
3636

3737
/// Bundle this string is in
38-
public let bundle: NSBundle
38+
public let bundle: Bundle
3939

4040
/// Locales of the a localizable string
4141
public let locales: [String]
4242

4343
/// Comment directly before and/or after the string, if any
4444
public let comment: String?
4545

46-
public init(key: String, tableName: String, bundle: NSBundle, locales: [String], comment: String?) {
46+
public init(key: String, tableName: String, bundle: Bundle, locales: [String], comment: String?) {
4747
self.key = key
4848
self.tableName = tableName
4949
self.bundle = bundle

Library/Core/Validatable.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
/// Error thrown during validation
12-
public struct ValidationError: ErrorType, CustomStringConvertible {
12+
public struct ValidationError: Error, CustomStringConvertible {
1313
/// Human readable description
1414
public let description: String
1515

@@ -35,11 +35,11 @@ extension Validatable {
3535
assert( theRealAssert() )
3636
}
3737

38-
private static func theRealAssert() -> Bool {
38+
fileprivate static func theRealAssert() -> Bool {
3939
do {
4040
try validate()
4141
} catch {
42-
assertionFailure("Validation of \(self.dynamicType) failed with error: \(error)")
42+
assertionFailure("Validation of \(type(of: self)) failed with error: \(error)")
4343
}
4444

4545
return true
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// NSBundle+FileResource.swift
2+
// Bundle+FileResource.swift
33
// R.swift.Library
44
//
55
// Created by Mathijs Kadijk on 10-01-16.
@@ -8,16 +8,16 @@
88

99
import Foundation
1010

11-
public extension NSBundle {
11+
public extension Bundle {
1212
/**
1313
Returns the file URL for the given resource (R.file.*).
1414

1515
- parameter resource: The resource to get the file URL for (R.file.*).
1616

1717
- returns: The file URL for the resource file (R.file.*) or nil if the file could not be located.
1818
*/
19-
public func URLForResource(resource: FileResourceType) -> NSURL? {
20-
return URLForResource(resource.name, withExtension: resource.pathExtension)
19+
public func url(forResource resource: FileResourceType) -> URL? {
20+
return url(forResource: resource.name, withExtension: resource.pathExtension)
2121
}
2222

2323
/**
@@ -27,7 +27,7 @@ public extension NSBundle {
2727

2828
- returns: The full pathname for the resource file (R.file.*) or nil if the file could not be located.
2929
*/
30-
public func pathForResource(resource: FileResourceType) -> String? {
31-
return pathForResource(resource.name, ofType: resource.pathExtension)
30+
public func path(forResource resource: FileResourceType) -> String? {
31+
return path(forResource: resource.name, ofType: resource.pathExtension)
3232
}
3333
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// NSData+FileResource.swift
2+
// Data+FileResource.swift
33
// R.swift.Library
44
//
55
// Created by Tom Lokhorst on 2016-03-11.
@@ -8,7 +8,9 @@
88

99
import Foundation
1010

11-
public extension NSData {
11+
public struct NoUrlForResourceError: Error {}
12+
13+
public extension Data {
1214

1315
/**
1416
Creates and returns NSData with the contents of the specified file resource (R.file.*).
@@ -17,8 +19,8 @@ public extension NSData {
1719

1820
- returns: A NSData object with the contents of the specified file.
1921
*/
20-
public convenience init?(resource: FileResourceType) {
21-
guard let url = resource.url() else { return nil }
22-
self.init(contentsOfURL: url)
22+
public init(resource: FileResourceType) throws {
23+
guard let url = resource.url() else { throw NoUrlForResourceError() }
24+
try self.init(contentsOf: url)
2325
}
2426
}

Library/UIKit/NibResource+UIKit.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public extension NibResourceType {
1818

1919
- returns: An array containing the top-level objects from the NIB
2020
*/
21-
public func instantiateWithOwner(ownerOrNil: AnyObject?, options optionsOrNil: [NSObject : AnyObject]? = nil) -> [AnyObject] {
22-
return UINib(resource: self).instantiateWithOwner(ownerOrNil, options: optionsOrNil)
21+
public func instantiate(withOwner ownerOrNil: Any?, options optionsOrNil: [AnyHashable : Any]? = [:]) -> [Any] {
22+
return UINib(resource: self).instantiate(withOwner: ownerOrNil, options: optionsOrNil)
2323
}
2424
}

Library/UIKit/StoryboardResourceWithInitialController+UIKit.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public extension StoryboardResourceWithInitialControllerType {
1515

1616
- returns: The initial view controller in the storyboard.
1717
*/
18-
public func initialViewController() -> InitialController? {
18+
public func instantiateInitialViewController() -> InitialController? {
1919
return UIStoryboard(resource: self).instantiateInitialViewController() as? InitialController
2020
}
2121
}

Library/UIKit/TypedStoryboardSegueInfo+UIStoryboardSegue.swift

+10-9
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ extension TypedStoryboardSegueInfo {
1515

1616
- returns: A newly initialized TypedStoryboardSegueInfo object or nil.
1717
*/
18-
public init?<SegueIdentifier: StoryboardSegueIdentifierType where SegueIdentifier.SegueType == Segue, SegueIdentifier.SourceType == Source, SegueIdentifier.DestinationType == Destination>(segueIdentifier: SegueIdentifier, segue: UIStoryboardSegue) {
18+
public init?<SegueIdentifier: StoryboardSegueIdentifierType>(segueIdentifier: SegueIdentifier, segue: UIStoryboardSegue)
19+
where SegueIdentifier.SegueType == Segue, SegueIdentifier.SourceType == Source, SegueIdentifier.DestinationType == Destination
20+
{
1921
guard let identifier = segue.identifier,
20-
sourceViewController = segue.sourceViewController as? SegueIdentifier.SourceType,
21-
destinationViewController = segue.destinationViewController as? SegueIdentifier.DestinationType,
22-
segue = segue as? SegueIdentifier.SegueType
23-
where identifier == segueIdentifier.identifier
24-
else {
25-
return nil
22+
let source = segue.source as? SegueIdentifier.SourceType,
23+
let destination = segue.destination as? SegueIdentifier.DestinationType,
24+
let segue = segue as? SegueIdentifier.SegueType, identifier == segueIdentifier.identifier
25+
else {
26+
return nil
2627
}
2728

2829
self.segue = segue
2930
self.identifier = identifier
30-
self.sourceViewController = sourceViewController
31-
self.destinationViewController = destinationViewController
31+
self.source = source
32+
self.destination = destination
3233
}
3334
}

Library/UIKit/UICollectionView+ReuseIdentifierProtocol.swift

+24-12
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public extension UICollectionView {
1818

1919
- returns: A subclass of UICollectionReusableView or nil if the cast fails.
2020
*/
21-
public func dequeueReusableCellWithReuseIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UICollectionReusableView>(identifier: Identifier, forIndexPath indexPath: NSIndexPath) -> Identifier.ReusableType? {
22-
return dequeueReusableCellWithReuseIdentifier(identifier.identifier, forIndexPath: indexPath) as? Identifier.ReusableType
21+
public func dequeueReusableCell<Identifier: ReuseIdentifierType>(withReuseIdentifier identifier: Identifier, for indexPath: IndexPath) -> Identifier.ReusableType?
22+
where Identifier.ReusableType: UICollectionReusableView
23+
{
24+
return dequeueReusableCell(withReuseIdentifier: identifier.identifier, for: indexPath) as? Identifier.ReusableType
2325
}
2426

2527
/**
@@ -31,43 +33,53 @@ public extension UICollectionView {
3133

3234
- returns: A subclass of UICollectionReusableView or nil if the cast fails.
3335
*/
34-
public func dequeueReusableSupplementaryViewOfKind<Identifier: ReuseIdentifierType where Identifier.ReusableType: UICollectionReusableView>(elementKind: String, withReuseIdentifier identifier: Identifier, forIndexPath indexPath: NSIndexPath) -> Identifier.ReusableType? {
35-
return dequeueReusableSupplementaryViewOfKind(elementKind, withReuseIdentifier: identifier.identifier, forIndexPath: indexPath) as? Identifier.ReusableType
36+
public func dequeueReusableSupplementaryView<Identifier: ReuseIdentifierType>(ofKind elementKind: String, withReuseIdentifier identifier: Identifier, for indexPath: IndexPath) -> Identifier.ReusableType?
37+
where Identifier.ReusableType: UICollectionReusableView
38+
{
39+
return dequeueReusableSupplementaryView(ofKind: elementKind, withReuseIdentifier: identifier.identifier, for: indexPath) as? Identifier.ReusableType
3640
}
3741

3842
/**
3943
Register a serie of R.nib.* for use in creating new collection view cells.
4044

4145
- parameter nibResources: An array of nib resources (R.nib.*) each containing a object of type UICollectionViewCell that has a reuse identifier
4246
*/
43-
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell>(nibResources: [Resource]) {
44-
nibResources.forEach(registerNib)
47+
public func register<Resource: NibResourceType>(_ nibResources: [Resource])
48+
where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell
49+
{
50+
nibResources.forEach(register)
4551
}
4652

4753
/**
4854
Register a R.nib.* for use in creating new collection view cells.
4955

5056
- parameter nibResource: A nib resource (R.nib.*) containing a object of type UICollectionViewCell that has a reuse identifier
5157
*/
52-
public func registerNib<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell>(nibResource: Resource) {
53-
registerNib(UINib(resource: nibResource), forCellWithReuseIdentifier: nibResource.identifier)
58+
public func register<Resource: NibResourceType>(_ nibResource: Resource)
59+
where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell
60+
{
61+
register(UINib(resource: nibResource), forCellWithReuseIdentifier: nibResource.identifier)
5462
}
5563

5664
/**
5765
Register a serie of R.nib.* for use in creating supplementary views for the collection view.
5866

5967
- parameter nibResources: An array of nib resources (R.nib.*) each containing a object of type UICollectionReusableView. that has a reuse identifier
6068
*/
61-
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionReusableView>(nibResources: [Resource], forSupplementaryViewOfKind kind: String) {
62-
nibResources.forEach { self.registerNib($0, forSupplementaryViewOfKind: kind) }
69+
public func register<Resource: NibResourceType>(_ nibResources: [Resource], forSupplementaryViewOfKind kind: String)
70+
where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionReusableView
71+
{
72+
nibResources.forEach { self.register($0, forSupplementaryViewOfKind: kind) }
6373
}
6474

6575
/**
6676
Register a R.nib.* for use in creating supplementary views for the collection view.
6777

6878
- parameter nibResource: A nib resource (R.nib.*) containing a object of type UICollectionReusableView. that has a reuse identifier
6979
*/
70-
public func registerNib<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionReusableView>(nibResource: Resource, forSupplementaryViewOfKind kind: String) {
71-
registerNib(UINib(resource: nibResource), forSupplementaryViewOfKind: kind, withReuseIdentifier: nibResource.identifier)
80+
public func register<Resource: NibResourceType>(_ nibResource: Resource, forSupplementaryViewOfKind kind: String)
81+
where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionReusableView
82+
{
83+
register(UINib(resource: nibResource), forSupplementaryViewOfKind: kind, withReuseIdentifier: nibResource.identifier)
7284
}
7385
}

0 commit comments

Comments
 (0)