R.swift
R.swift copied to clipboard
Bug In pod lib create,generate file build faild
Step here:
- create a swift pod
pod lib create HomeModule
- add dependency in HomeModule.podspec file ( s.dependency 'R.swift', '6.1.0' )
- new nib file to dev pod
- add script in Example's Podfile and run pod install
- build project and add R.generated.swift to dev pod
- 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
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 :)
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 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...
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.
This is now fixed in version 7.0.0