R.swift: Not correctly validate storyboard in submodule

Created on 27 Jun 2018  路  6Comments  路  Source: mac-cain13/R.swift

Hi!

I'm using R.validate() in a submodule test case and it throws an exception due to a missing UIImage in storyboard. If I launch my app and I go to the controller with that "missing" UIImage, the app does not crash and shows correctly that UIImage.
Maybe should I declare the host bundle in some place (like storyboard?) or something?

Most helpful comment

same problem: https://twitter.com/Cooler333/status/1052508604266409984

    struct someSome: Rswift.StoryboardResourceWithInitialControllerType, Rswift.Validatable {
      typealias InitialController = SOMESome

      let bundle = R.hostingBundle // unused
      let name = "SOMESome" // unused too, but it's minor issue

      static func validate() throws {
        if UIKit.UIImage(named: "some_some" /*, in: bundle*/ ) == nil { throw Rswift.ValidationError(description: "[R.swift] Image named 'some_some' is used in storyboard 'SOMESome', but couldn't be loaded.") }
      }

      fileprivate init() {}
    }

UIImage missing argument for bundle

    @available(iOS 8.0, *)
    public /*not inherited*/ init?(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?)

but used

    public /*not inherited*/ init?(named name: String) // load from main bundle

All 6 comments

Would you be able to provide us with a reproduction sample? Then we can look into this and fix it. If a sample app is too much work it would be nice to know:

  • What code was generated in the validate() method by R.swift for this image?
  • If you run that code from your app, does it load the image correctly?
  • Did you customize any settings for this image in the asset catalog?
  • In what bundle are the asset catalog and the storyboard located?

Thank you for replying me. I have created a sample app with a submodule, using cocoapods. There are two unit tests checking if all images in storyboards are correctly loaded, by calling R.validate().
If you run the app, you can see all images are correctly visible. But if you test the app, the Submodule unit test fails, because of ic_code is missing from the bundle.

SampleApp.zip

same problem: https://twitter.com/Cooler333/status/1052508604266409984

    struct someSome: Rswift.StoryboardResourceWithInitialControllerType, Rswift.Validatable {
      typealias InitialController = SOMESome

      let bundle = R.hostingBundle // unused
      let name = "SOMESome" // unused too, but it's minor issue

      static func validate() throws {
        if UIKit.UIImage(named: "some_some" /*, in: bundle*/ ) == nil { throw Rswift.ValidationError(description: "[R.swift] Image named 'some_some' is used in storyboard 'SOMESome', but couldn't be loaded.") }
      }

      fileprivate init() {}
    }

UIImage missing argument for bundle

    @available(iOS 8.0, *)
    public /*not inherited*/ init?(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?)

but used

    public /*not inherited*/ init?(named name: String) // load from main bundle

This also affects named colors, the solution would be the same, to use the bundle parameter with the value of R.hostingBundle

@rolandkakonyi add fix for colors in PR :)

This should be fix as of 5.0.0.alpha.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jalone87 picture jalone87  路  6Comments

theamorn picture theamorn  路  4Comments

alexpersian picture alexpersian  路  6Comments

vladimirvrabelml picture vladimirvrabelml  路  7Comments

aliasdoc picture aliasdoc  路  3Comments