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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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
Lines changed: 6 additions & 6 deletions
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
}
Lines changed: 7 additions & 5 deletions
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
}

0 commit comments

Comments
 (0)