Skip to content

Commit 151210a

Browse files
authored
Merge pull request mac-cain13#24 from mac-cain13/release/4.0
Release/4.0
2 parents 594965c + d8390c2 commit 151210a

13 files changed

+141
-275
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// ColorPaletteItemResource.swift
3+
// R.swift.Library
4+
//
5+
// Created by Tom Lokhorst on 2016-03-13.
6+
// From: https://github.com/mac-cain13/R.swift.Library
7+
// License: MIT License
8+
//
9+
10+
import Foundation
11+
12+
public protocol ColorPaletteItemResourceType {
13+
14+
/// Name of the color
15+
var name: String { get }
16+
17+
/// Red componenent of color
18+
var red: CGFloat { get }
19+
20+
/// Green componenent of color
21+
var green: CGFloat { get }
22+
23+
/// Blue componenent of color
24+
var blue: CGFloat { get }
25+
26+
/// Alpha componenent of color
27+
var alpha: CGFloat { get }
28+
}
29+
30+
@available(*, deprecated: 11, message: "Use color assets instead")
31+
public struct ColorPaletteItemResource: ColorPaletteItemResourceType {
32+
33+
/// Name of the color
34+
public let name: String
35+
36+
/// Red componenent of color
37+
public let red: CGFloat
38+
39+
/// Green componenent of color
40+
public let green: CGFloat
41+
42+
/// Blue componenent of color
43+
public let blue: CGFloat
44+
45+
/// Alpha componenent of color
46+
public let alpha: CGFloat
47+
48+
public init(name: String, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
49+
self.name = name
50+
self.red = red
51+
self.green = green
52+
self.blue = blue
53+
self.alpha = alpha
54+
}
55+
}

Library/Core/ColorResource.swift

+8-29
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,23 @@ import Foundation
1111

1212
public protocol ColorResourceType {
1313

14+
/// Bundle this color is in
15+
var bundle: Bundle { get }
16+
1417
/// Name of the color
1518
var name: String { get }
16-
17-
/// Red componenent of color
18-
var red: CGFloat { get }
19-
20-
/// Green componenent of color
21-
var green: CGFloat { get }
22-
23-
/// Blue componenent of color
24-
var blue: CGFloat { get }
25-
26-
/// Alpha componenent of color
27-
var alpha: CGFloat { get }
2819
}
2920

3021
public struct ColorResource: ColorResourceType {
3122

23+
/// Bundle this color is in
24+
public let bundle: Bundle
25+
3226
/// Name of the color
3327
public let name: String
3428

35-
/// Red componenent of color
36-
public let red: CGFloat
37-
38-
/// Green componenent of color
39-
public let green: CGFloat
40-
41-
/// Blue componenent of color
42-
public let blue: CGFloat
43-
44-
/// Alpha componenent of color
45-
public let alpha: CGFloat
46-
47-
public init(name: String, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
29+
public init(bundle: Bundle, name: String) {
30+
self.bundle = bundle
4831
self.name = name
49-
self.red = red
50-
self.green = green
51-
self.blue = blue
52-
self.alpha = alpha
5332
}
5433
}

Library/Core/Core+Migration.swift

-42
This file was deleted.

Library/Core/Validatable.swift

-20
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,3 @@ public protocol Validatable {
2727
*/
2828
static func validate() throws
2929
}
30-
31-
extension Validatable {
32-
/**
33-
Validates this entity and asserts if it encounters a invalid situation, a validatable should also validate it sub-validatables if it has any. In -O builds (the default for Xcode's Release configuration), validation is not evaluated, and there are no effects.
34-
*/
35-
@available(*, deprecated, message: "Use validate() instead, preferably from a testcase.")
36-
public static func assertValid() {
37-
assert( theRealAssert() )
38-
}
39-
40-
fileprivate static func theRealAssert() -> Bool {
41-
do {
42-
try validate()
43-
} catch {
44-
assertionFailure("Validation of \(type(of: self)) failed with error: \(error)")
45-
}
46-
47-
return true
48-
}
49-
}

Library/Foundation/Foundation+Migration.swift

-26
This file was deleted.

Library/UIKit/ColorResource+UIKit.swift renamed to Library/UIKit/ColorPaletteItemResource+UIKit.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// ColorResource+UIKit.swift
2+
// ColorPaletteItemResource+UIKit.swift
33
// R.swift.Library
44
//
55
// Created by Tom Lokhorst on 2016-04-23.
@@ -9,11 +9,11 @@
99

1010
import UIKit
1111

12-
public extension ColorResourceType {
12+
public extension ColorPaletteItemResourceType {
1313
/**
1414
Returns the a UIColor
1515

16-
- returns: A UIColor for this color resource
16+
- returns: A UIColor for this color palette item resource
1717
*/
1818
func color() -> UIColor {
1919
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// UIColor+ColorResource.swift
3+
// R.swift.Library
4+
//
5+
// Created by Tom Lokhorst on 2017-06-06.
6+
// From: https://github.com/mac-cain13/R.swift.Library
7+
// License: MIT License
8+
//
9+
10+
import UIKit
11+
12+
@available(iOS 11.0, *)
13+
@available(tvOS 11.0, *)
14+
public extension UIColor {
15+
/**
16+
Returns the color from this resource (R.color.*) that is compatible with the trait collection.
17+
18+
- parameter resource: The resource you want the image of (R.color.*)
19+
- parameter traitCollection: Traits that describe the desired color to retrieve, pass nil to use traits that describe the main screen.
20+
21+
- returns: A color that exactly or best matches the desired traits with the given resource (R.color.*), or nil if no suitable color was found.
22+
*/
23+
public convenience init?(resource: ColorResourceType, compatibleWith traitCollection: UITraitCollection? = nil) {
24+
self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
25+
}
26+
}

Library/UIKit/UIKit+Migration.swift

-120
This file was deleted.

R.swift.Library.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |spec|
22

33
spec.name = "R.swift.Library"
4-
spec.version = "3.0.2"
4+
spec.version = "4.0.0.alpha.2"
55
spec.license = "MIT"
66

77
spec.summary = "Companion library for R.swift, featuring types used to type resources"

0 commit comments

Comments
 (0)