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

Commit 4002f22

Browse files
authored
Merge pull request #28 from lammertw/watchos
Add basic watchOS support
2 parents ae88152 + 997b6e5 commit 4002f22

File tree

6 files changed

+234
-42
lines changed

6 files changed

+234
-42
lines changed

Library/UIKit/UIColor+ColorResource.swift

+17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import UIKit
1212
@available(iOS 11.0, *)
1313
@available(tvOS 11.0, *)
1414
public extension UIColor {
15+
16+
#if os(iOS) || os(tvOS)
1517
/**
1618
Returns the color from this resource (R.color.*) that is compatible with the trait collection.
1719

@@ -23,4 +25,19 @@ public extension UIColor {
2325
convenience init?(resource: ColorResourceType, compatibleWith traitCollection: UITraitCollection? = nil) {
2426
self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
2527
}
28+
#endif
29+
30+
#if os(watchOS)
31+
/**
32+
Returns the color from this resource (R.color.*) that is compatible with the trait collection.
33+
34+
- parameter resource: The resource you want the image of (R.color.*)
35+
36+
- 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.
37+
*/
38+
@available(watchOSApplicationExtension 4.0, *)
39+
convenience init?(resource: ColorResourceType) {
40+
self.init(named: resource.name)
41+
}
42+
#endif
2643
}

Library/UIKit/UIImage+ImageResource.swift

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import UIKit
1111

1212
public extension UIImage {
13+
14+
#if os(iOS) || os(tvOS)
1315
/**
1416
Returns the image from this resource (R.image.*) that is compatible with the trait collection.
1517

@@ -21,4 +23,18 @@ public extension UIImage {
2123
convenience init?(resource: ImageResourceType, compatibleWith traitCollection: UITraitCollection? = nil) {
2224
self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
2325
}
26+
#endif
27+
28+
#if os(watchOS)
29+
/**
30+
Returns the image from this resource (R.image.*) that is compatible with the trait collection.
31+
32+
- parameter resource: The resource you want the image of (R.image.*)
33+
34+
- 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.
35+
*/
36+
convenience init?(resource: ImageResourceType) {
37+
self.init(named: resource.name)
38+
}
39+
#endif
2440
}

R.swift.Library.podspec

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ Pod::Spec.new do |spec|
2121
spec.pod_target_xcconfig = { 'APPLICATION_EXTENSION_API_ONLY' => 'YES' }
2222

2323
spec.ios.deployment_target = '8.0'
24+
spec.ios.source_files = "Library/**/*.swift"
2425
spec.tvos.deployment_target = '9.0'
26+
spec.tvos.source_files = "Library/**/*.swift"
27+
spec.watchos.deployment_target = '2.2'
28+
spec.watchos.source_files = ["Library/Core/*.swift", "Library/Foundation/*.swift"]
2529

2630
spec.module_name = "Rswift"
27-
spec.source_files = "Library/**/*.swift"
2831

2932
end

0 commit comments

Comments
 (0)