R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Bug In pod lib create,generate file build faild

Open Cheng455153666 opened this issue 3 years ago • 4 comments

Step here:

  1. create a swift pod pod lib create HomeModule
  2. add dependency in HomeModule.podspec file ( s.dependency 'R.swift', '6.1.0' )
  3. new nib file to dev pod
  4. add script in Example's Podfile and run pod install
  5. build project and add R.generated.swift to dev pod
  6. everything is ok with out XIB o(╥﹏╥)o
# R.generated.swift
# build failed
R.nib.myCus02ViewController.instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? UIKit.UIView
# so I change to ↓,it's work
UIKit.UINib(resource: R.nib.myCus02ViewController).instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? UIKit.UIView

Example Here

Cheng455153666 avatar Dec 10 '21 08:12 Cheng455153666

I am also have the same problem:

 static func myCustomView(owner ownerOrNil: AnyObject?, options optionsOrNil: [UINib.OptionsKey : Any]? = nil) -> myCustomView? {
      return R.nib.myCustomView.instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? myCustomView
    }

This code shows an error:

Value of type '_R.nib._myCustomView' has no member 'instantiate'

This sample has a similar error

func firstView(owner ownerOrNil: AnyObject?, options optionsOrNil: [UINib.OptionsKey : Any]? = nil) -> myCustomView? {
        return instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? myCustomView
      }
Cannot find 'instantiate' in scope

Thank you @Cheng455153666 for solution, but this bug should be fixed in a proper way in R lib :)

hjcn1337 avatar Dec 16 '21 10:12 hjcn1337

I can reproduce the error when I use your example, but I don't understand what causes it.

The method instantiate(withOwner:options:) is an extension on NibResourceType that is part of R.swift.Library.

For some reason this extension method isn't available in your Xcode project, but I don't know why that is.

tomlokhorst avatar Dec 16 '21 12:12 tomlokhorst

@tomlokhorst In my project I was in migration process from 4.0.0 to 6.1.0 and found that errors were appeared beginning from 5.1.0. With 5.0.3 version I get successful build. I have m1 pro Mac.

Hope this information helps you...

hjcn1337 avatar Dec 16 '21 12:12 hjcn1337

I am also have the same problem:

 static func myCustomView(owner ownerOrNil: AnyObject?, options optionsOrNil: [UINib.OptionsKey : Any]? = nil) -> myCustomView? {
      return R.nib.myCustomView.instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? myCustomView
    }

This code shows an error:

Value of type '_R.nib._myCustomView' has no member 'instantiate'

This sample has a similar error

func firstView(owner ownerOrNil: AnyObject?, options optionsOrNil: [UINib.OptionsKey : Any]? = nil) -> myCustomView? {
        return instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? myCustomView
      }
Cannot find 'instantiate' in scope

Thank you @Cheng455153666 for solution, but this bug should be fixed in a proper way in R lib :)

Yes, I agree. Finally, I created a copy of R.swift, and modified the code to generate Xib code.

In NibStructGenerator.swift:

...

line 105 : body: "return UIKit.UINib(resource: \(qualifiedCurrentNibName)).instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? \(firstViewInfo)",

...

line 180 : body: "return UIKit.UINib(resource: R.nib.\(SwiftIdentifier(name: nib.name))).instantiate(withOwner: ownerOrNil, options: optionsOrNil)[\(viewIndex)] as? \(viewTypeString)",

Regenerated rswift executable file, and replace. it's work.

Cheng455153666 avatar Dec 23 '21 06:12 Cheng455153666

This is now fixed in version 7.0.0

tomlokhorst avatar Nov 28 '22 14:11 tomlokhorst