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

Conversation

lammertw
Copy link
Contributor

This basically disabled all functions for watchOS that are not supported by the watchOS sdk by wrapping them in preprocessor statements.

For example:

#if os(iOS) || os(tvOS)
/// `UIImage(named: "Utilitarian", bundle: ..., traitCollection: ...)`
static func utilitarian(compatibleWith traitCollection: UIKit.UITraitCollection? = nil) -> UIKit.UIImage? {
  return UIKit.UIImage(resource: R.image.utilitarian, compatibleWith: traitCollection)
}
#endif

@tomlokhorst
Copy link
Collaborator

Thanks for this PR!

It's been a while, but I'm finally working om merging this.

I'm getting a build error about watchOS not knowing UITraitCollection, when I try to build the Rswift-watchOS target in this library. I'm guessing those files shouldn't be part of the Watch target at all?

@lammertw
Copy link
Contributor Author

That's correct. I guess there is some new code added using UITraitCollection. If you look in for example UIColor+ColorResource.swift you can see how to deal with that:

  #if os(iOS) || os(tvOS)
  /**
   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.*)
   - parameter traitCollection: Traits that describe the desired color to retrieve, pass nil to use traits that describe the main screen.

   - 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.
   */
  public convenience init?(resource: ColorResourceType, compatibleWith traitCollection: UITraitCollection? = nil) {
    self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
  }
  #endif

@fnuky
Copy link

fnuky commented Jan 14, 2019

Hi! How it looks? I started adding watch support because it would be good for me and I'm looking and here is this PR already :).

@tomlokhorst
Copy link
Collaborator

@lammertw I'm not seeing that #if os(iOS) || os(tvOS) in this PR

@lammertw
Copy link
Contributor Author

Right, I just noticed it as well. It seems I added this code once locally at a later time after merging in a new version but never put that into this pull request. I've pushed it now.

@teameh
Copy link

teameh commented May 7, 2019

Any updates on this? Would be great if this could be merged in :)

@tomlokhorst tomlokhorst merged commit 4002f22 into mac-cain13:master Jun 10, 2019
@tomlokhorst
Copy link
Collaborator

Merging with mac-cain13/R.swift#441

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants