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

Add basic watchOS support #28

Merged
merged 5 commits into from
Jun 10, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix code for different platforms
  • Loading branch information
lammertw committed Jan 14, 2019
commit d6eba6f7f42ac5a10c73309f1ed63f43f42af38c
17 changes: 17 additions & 0 deletions Library/UIKit/UIColor+ColorResource.swift
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ import UIKit
@available(iOS 11.0, *)
@available(tvOS 11.0, *)
public extension UIColor {

#if os(iOS) || os(tvOS)
/**
Returns the color from this resource (R.color.*) that is compatible with the trait collection.

@@ -23,4 +25,19 @@ public extension UIColor {
public convenience init?(resource: ColorResourceType, compatibleWith traitCollection: UITraitCollection? = nil) {
self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
}
#endif

#if os(watchOS)
/**
Returns the color from this resource (R.color.*) that is compatible with the trait collection.

- parameter resource: The resource you want the image of (R.color.*)

- 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.
*/
@available(watchOSApplicationExtension 4.0, *)
public convenience init?(resource: ColorResourceType) {
self.init(named: resource.name)
}
#endif
}
16 changes: 16 additions & 0 deletions Library/UIKit/UIImage+ImageResource.swift
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
import UIKit

public extension UIImage {

#if os(iOS) || os(tvOS)
/**
Returns the image from this resource (R.image.*) that is compatible with the trait collection.

@@ -21,4 +23,18 @@ public extension UIImage {
public convenience init?(resource: ImageResourceType, compatibleWith traitCollection: UITraitCollection? = nil) {
self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
}
#endif

#if os(watchOS)
/**
Returns the image from this resource (R.image.*) that is compatible with the trait collection.

- parameter resource: The resource you want the image of (R.image.*)

- 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.
*/
public convenience init?(resource: ImageResourceType) {
self.init(named: resource.name)
}
#endif
}