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

Commit fe1785e

Browse files
committed
Run Swift 3 conversion
1 parent 326e89b commit fe1785e

17 files changed

+73
-74
lines changed

Diff for: Library/Core/FileResource.swift

+5-5
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
/**
@@ -40,22 +40,22 @@ public extension FileResourceType {
4040

4141
- returns: The file URL for this resource or nil if the file could not be located.
4242
*/
43-
func url() -> NSURL? {
43+
func url() -> URL? {
4444
return bundle.URLForResource(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

Diff for: 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
}

Diff for: 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 }

Diff for: 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 }

Diff for: Library/Core/StoryboardSegueIdentifierProtocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ 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 storyboardSegueWithSource(_ sourceViewController: Source)
4848
-> StoryboardSegue<Segue, Source, Destination>
4949
{
5050
return StoryboardSegue(identifier: self, sourceViewController: sourceViewController)

Diff for: Library/Core/Validatable.swift

+1-1
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: ErrorProtocol, CustomStringConvertible {
1313
/// Human readable description
1414
public let description: String
1515

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 URLForResource(_ resource: FileResourceType) -> URL? {
20+
return urlForResource(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? {
30+
public func pathForResource(_ resource: FileResourceType) -> String? {
3131
return pathForResource(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,7 @@
88

99
import Foundation
1010

11-
public extension NSData {
11+
public extension Data {
1212

1313
/**
1414
Creates and returns NSData with the contents of the specified file resource (R.file.*).
@@ -17,8 +17,8 @@ public extension NSData {
1717

1818
- returns: A NSData object with the contents of the specified file.
1919
*/
20-
public convenience init?(resource: FileResourceType) {
20+
public init?(resource: FileResourceType) throws {
2121
guard let url = resource.url() else { return nil }
22-
self.init(contentsOfURL: url)
22+
try self.init(contentsOf: url)
2323
}
2424
}

Diff for: 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 instantiateWithOwner(_ ownerOrNil: AnyObject?, options optionsOrNil: [NSObject : AnyObject]? = nil) -> [AnyObject] {
22+
return UINib(resource: self).instantiate(withOwner: ownerOrNil, options: optionsOrNil)
2323
}
2424
}

Diff for: Library/UIKit/TypedStoryboardSegueInfo+UIStoryboardSegue.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ extension TypedStoryboardSegueInfo {
1717
*/
1818
public init?<SegueIdentifier: StoryboardSegueIdentifierType where SegueIdentifier.SegueType == Segue, SegueIdentifier.SourceType == Source, SegueIdentifier.DestinationType == Destination>(segueIdentifier: SegueIdentifier, segue: UIStoryboardSegue) {
1919
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
20+
let sourceViewController = segue.sourceViewController as? SegueIdentifier.SourceType,
21+
let destinationViewController = segue.destinationViewController as? SegueIdentifier.DestinationType,
22+
let segue = segue as? SegueIdentifier.SegueType, identifier == segueIdentifier.identifier
23+
else {
24+
return nil
2625
}
2726

2827
self.segue = segue

Diff for: Library/UIKit/UICollectionView+ReuseIdentifierProtocol.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ 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 dequeueReusableCellWithReuseIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UICollectionReusableView>(_ identifier: Identifier, forIndexPath indexPath: IndexPath) -> Identifier.ReusableType? {
22+
return dequeueReusableCell(withReuseIdentifier: identifier.identifier, for: indexPath) as? Identifier.ReusableType
2323
}
2424

2525
/**
@@ -31,16 +31,16 @@ public extension UICollectionView {
3131

3232
- returns: A subclass of UICollectionReusableView or nil if the cast fails.
3333
*/
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
34+
public func dequeueReusableSupplementaryViewOfKind<Identifier: ReuseIdentifierType where Identifier.ReusableType: UICollectionReusableView>(_ elementKind: String, withReuseIdentifier identifier: Identifier, forIndexPath indexPath: IndexPath) -> Identifier.ReusableType? {
35+
return dequeueReusableSupplementaryView(ofKind: elementKind, withReuseIdentifier: identifier.identifier, for: indexPath) as? Identifier.ReusableType
3636
}
3737

3838
/**
3939
Register a serie of R.nib.* for use in creating new collection view cells.
4040

4141
- parameter nibResources: An array of nib resources (R.nib.*) each containing a object of type UICollectionViewCell that has a reuse identifier
4242
*/
43-
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell>(nibResources: [Resource]) {
43+
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell>(_ nibResources: [Resource]) {
4444
nibResources.forEach(registerNib)
4545
}
4646

@@ -49,16 +49,16 @@ public extension UICollectionView {
4949

5050
- parameter nibResource: A nib resource (R.nib.*) containing a object of type UICollectionViewCell that has a reuse identifier
5151
*/
52-
public func registerNib<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell>(nibResource: Resource) {
53-
registerNib(UINib(resource: nibResource), forCellWithReuseIdentifier: nibResource.identifier)
52+
public func registerNib<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionViewCell>(_ nibResource: Resource) {
53+
register(UINib(resource: nibResource), forCellWithReuseIdentifier: nibResource.identifier)
5454
}
5555

5656
/**
5757
Register a serie of R.nib.* for use in creating supplementary views for the collection view.
5858

5959
- parameter nibResources: An array of nib resources (R.nib.*) each containing a object of type UICollectionReusableView. that has a reuse identifier
6060
*/
61-
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionReusableView>(nibResources: [Resource], forSupplementaryViewOfKind kind: String) {
61+
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionReusableView>(_ nibResources: [Resource], forSupplementaryViewOfKind kind: String) {
6262
nibResources.forEach { self.registerNib($0, forSupplementaryViewOfKind: kind) }
6363
}
6464

@@ -67,7 +67,7 @@ public extension UICollectionView {
6767

6868
- parameter nibResource: A nib resource (R.nib.*) containing a object of type UICollectionReusableView. that has a reuse identifier
6969
*/
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)
70+
public func registerNib<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UICollectionReusableView>(_ nibResource: Resource, forSupplementaryViewOfKind kind: String) {
71+
register(UINib(resource: nibResource), forSupplementaryViewOfKind: kind, withReuseIdentifier: nibResource.identifier)
7272
}
7373
}

Diff for: Library/UIKit/UIImage+ImageResource.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public extension UIImage {
1818
- returns: An image that exactly or best matches the desired traits with the given resource (R.image.*), or nil if no suitable image was found.
1919
*/
2020
public convenience init?(resource: ImageResourceType, compatibleWithTraitCollection traitCollection: UITraitCollection? = nil) {
21-
self.init(named: resource.name, inBundle: resource.bundle, compatibleWithTraitCollection: traitCollection)
21+
self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
2222
}
2323
}

Diff for: Library/UIKit/UIStoryboard+StoryboardViewControllerResource.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public extension UIStoryboard {
1717

1818
- returns: The view controller corresponding to the specified resource (R.storyboard.*.*). If no view controller is associated, this method throws an exception.
1919
*/
20-
public func instantiateViewController<ViewControllerResource: StoryboardViewControllerResourceType>(resource: ViewControllerResource) -> ViewControllerResource.ViewControllerType? {
21-
return instantiateViewControllerWithIdentifier(resource.identifier) as? ViewControllerResource.ViewControllerType
20+
public func instantiateViewController<ViewControllerResource: StoryboardViewControllerResourceType>(_ resource: ViewControllerResource) -> ViewControllerResource.ViewControllerType? {
21+
return self.instantiateViewController(withIdentifier: resource.identifier) as? ViewControllerResource.ViewControllerType
2222
}
2323
}

Diff for: Library/UIKit/UITableView+ReuseIdentifierProtocol.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public extension UITableView {
2020

2121
- precondition: You must register a class or nib file using the registerNib: or registerClass:forCellReuseIdentifier: method before calling this method.
2222
*/
23-
public func dequeueReusableCellWithIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UITableViewCell>(identifier: Identifier, forIndexPath indexPath: NSIndexPath) -> Identifier.ReusableType? {
24-
return dequeueReusableCellWithIdentifier(identifier.identifier, forIndexPath: indexPath) as? Identifier.ReusableType
23+
public func dequeueReusableCellWithIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UITableViewCell>(_ identifier: Identifier, forIndexPath indexPath: IndexPath) -> Identifier.ReusableType? {
24+
return dequeueReusableCell(withIdentifier: identifier.identifier, for: indexPath) as? Identifier.ReusableType
2525
}
2626

2727
/**
@@ -33,8 +33,8 @@ public extension UITableView {
3333

3434
- precondition: You must register a class or nib file using the registerNib: or registerClass:forCellReuseIdentifier: method before calling this method.
3535
*/
36-
public func dequeueReusableCellWithIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UITableViewCell>(identifier: Identifier) -> Identifier.ReusableType? {
37-
return dequeueReusableCellWithIdentifier(identifier.identifier) as? Identifier.ReusableType
36+
public func dequeueReusableCellWithIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UITableViewCell>(_ identifier: Identifier) -> Identifier.ReusableType? {
37+
return dequeueReusableCell(withIdentifier: identifier.identifier) as? Identifier.ReusableType
3838
}
3939

4040
/**
@@ -44,16 +44,16 @@ public extension UITableView {
4444

4545
- returns: A UITableViewHeaderFooterView object with the associated identifier or nil if no such object exists in the reusable view queue or if it couldn't be cast correctly.
4646
*/
47-
public func dequeueReusableHeaderFooterViewWithIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UITableViewHeaderFooterView>(identifier: Identifier) -> Identifier.ReusableType? {
48-
return dequeueReusableHeaderFooterViewWithIdentifier(identifier.identifier) as? Identifier.ReusableType
47+
public func dequeueReusableHeaderFooterViewWithIdentifier<Identifier: ReuseIdentifierType where Identifier.ReusableType: UITableViewHeaderFooterView>(_ identifier: Identifier) -> Identifier.ReusableType? {
48+
return dequeueReusableHeaderFooterView(withIdentifier: identifier.identifier) as? Identifier.ReusableType
4949
}
5050

5151
/**
5252
Register an array of R.nib.*, each containing a cell, with the table view under it's contained identifier.
5353

5454
- parameter nibResources: Array of nib resources (R.nib.*) each containing a table view cell that has a reuse identifier
5555
*/
56-
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UITableViewCell>(nibResources: [Resource]) {
56+
public func registerNibs<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UITableViewCell>(_ nibResources: [Resource]) {
5757
nibResources.forEach(registerNib)
5858
}
5959

@@ -62,16 +62,16 @@ public extension UITableView {
6262

6363
- parameter nibResource: A nib resource (R.nib.*) containing a table view cell that has a reuse identifier
6464
*/
65-
public func registerNib<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UITableViewCell>(nibResource: Resource) {
66-
registerNib(UINib(resource: nibResource), forCellReuseIdentifier: nibResource.identifier)
65+
public func registerNib<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UITableViewCell>(_ nibResource: Resource) {
66+
register(UINib(resource: nibResource), forCellReuseIdentifier: nibResource.identifier)
6767
}
6868

6969
/**
7070
Register a R.nib.* containing a header or footer with the table view under it's contained identifier.
7171

7272
- parameter nibResource: A nib resource (R.nib.*) containing a view that has a reuse identifier
7373
*/
74-
public func registerNibForHeaderFooterView<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UIView>(nibResource: Resource) {
75-
registerNib(UINib(resource: nibResource), forHeaderFooterViewReuseIdentifier: nibResource.identifier)
74+
public func registerNibForHeaderFooterView<Resource: NibResourceType where Resource: ReuseIdentifierType, Resource.ReusableType: UIView>(_ nibResource: Resource) {
75+
register(UINib(resource: nibResource), forHeaderFooterViewReuseIdentifier: nibResource.identifier)
7676
}
7777
}

Diff for: Library/UIKit/UIViewController+StoryboardSegueIdentifierProtocol.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
import UIKit
1111

1212
public protocol SeguePerformerType {
13-
func performSegueWithIdentifier(identifier: String, sender: AnyObject?)
13+
func performSegueWithIdentifier(_ identifier: String, sender: AnyObject?)
1414
}
1515

1616
extension UIViewController: SeguePerformerType { }
@@ -23,7 +23,7 @@ public extension SeguePerformerType {
2323
- SeeAlso: Library for typed block based segues: [tomlokhorst/SegueManager](https://github.com/tomlokhorst/SegueManager)
2424
*/
2525
public func performSegueWithIdentifier<Segue, Destination>(
26-
identifier: StoryboardSegueIdentifier<Segue, Self, Destination>,
26+
_ identifier: StoryboardSegueIdentifier<Segue, Self, Destination>,
2727
sender: AnyObject?) {
2828
performSegueWithIdentifier(identifier.identifier, sender: sender)
2929
}
@@ -34,7 +34,7 @@ public extension StoryboardSegue where Source : UIViewController {
3434
Performs this segue on the source view controller
3535
- parameter sender: The object that you want to use to initiate the segue. This object is made available for informational purposes during the actual segue.
3636
*/
37-
public func performSegue(sender: AnyObject? = nil) {
38-
sourceViewController.performSegueWithIdentifier(identifier.identifier, sender: sender)
37+
public func performSegue(_ sender: AnyObject? = nil) {
38+
sourceViewController.performSegue(withIdentifier: identifier.identifier, sender: sender)
3939
}
4040
}

Diff for: LibraryTests/RswiftTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RswiftTests: XCTestCase {
2828

2929
func testPerformanceExample() {
3030
// This is an example of a performance test case.
31-
self.measureBlock {
31+
self.measure {
3232
// Put the code you want to measure the time of here.
3333
}
3434
}

0 commit comments

Comments
 (0)