Comments (14)
from reusable.
I guess I formulated the title of this issue a bit harsh. Maybe this behavior was intended like this by you @AliSoftware ?
I just found it more intuitive to use the name of the dynamic type rather than the name of the base class. The place where this happens is in NibOwnerLoadable
's loadNibContent
Essentially Self
will always be the type that immediately declares conformance to the protocol (in my example that is MyCustomClass
). Changing that to type(of: self)
instead would give you the true dynamic type of the object and hence load the nib the the class' name.
@AliSoftware Do you think that is a reasonable change? If so, I can prepare a PR for you.
from reusable.
Mmmh interesting. I'm wondering if we could instead make sure that dynamic dispatch takes place on nib
property … but not sure it's entirely possible in our use case, so your suggestion makes sense I think, and I'd love a PR
from reusable.
Great. I'm not really sure that the dynamic dispatch can be achieved in the nib
property since to the computed property this seems to be equivalent to being called from the base class itself. Essentially the problem will be something like calling a static method on the dynamic type vs. calling it on a fixed metatype (e.g. like here https://stackoverflow.com/questions/42260337/swift-calling-static-methods-typeof-self-vs-explicit-class-name)
I created a PR with that small change where we can discuss this further if needed.
from reusable.
Closed by #96
from reusable.
Hi,
First of all thank you very much for this library, it has been very useful for the projects I've been working on. I have one question though, I believe the PR that fixes this broke our app, we got some crashes when creating an IBOutlet from a subclass, in the example provided it would be MyCustomSubClass
(fortunately we catch this before shipping).
My question is, when subclassing now the parent class needs to implement nib: UINib
otherwise there will be a crash. Was this a bug or that has been the intentional behavior?
Thanks in advance
from reusable.
Thanks for reporting this.
I don't think this was intentional; but I'm unsure why the nib
property would need to now always be implemented in the parent class explicitly if your IBOutlet points to a subclass and thus the PR fixing this issue is supposed to get the nib property from the subclass anyway
Could you maybe provide a simplified sample code so we can pinpoint what's happening?
from reusable.
Hi @AliSoftware, thanks for your reply.
Perhaps I explained myself incorrectly, there was no need of an IBOutlet, I am having the same crash if I add a NibOwnerLoadable
directly on a ViewController on a storyboard.
I created this simple project which has the same problem, the uncommitted change is what fixes the crash.
Let me know if I can help on something else.
Thanks
Btw, this is the crash:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <.../TestReusable.app> (loaded)' with name 'SubclassCustomTextField''
terminating with uncaught exception of type NSException
from reusable.
from reusable.
Did you try commenting out the uncommitted changes?
//static var nib: UINib {
// return UINib(nibName: "CustomTextField", bundle: Bundle(for: self))
//}
Doing this I can get the crash. Unless is the Xcode version I am using 12.0.1 (12A7300)
from reusable.
from reusable.
Ah ok got it, thank you very much for your reply.
Just wanted to make sure we are implementing it in the proper way and this is an expected behavior.
Unless @AliSoftware has something else to add
from reusable.
Thank you so much @calmez for looking into that and for giving such a detailed answer and thorough explanation
I think this can be considered the intended behavior for this case indeed now that I get the setup.
We can't really support both cases at the same time (the case where you have a single XIB for parent and subclasses, vs the case where you have one XIB for each subclass) anyway and have to pick one over the other in our choice of implementation
I think it could still be nice to mention something about this in the docs though (either in the README, or as doc comments in the code), with @calmez 's good explanation as a good start for the documentation copy
from reusable.
Ah ok got it, understood.
Thank you very much guys!
from reusable.
Related Issues (20)
- getting error on using cellType(for indexPath:)
- Support for new API introduced on iOS 13
- MKMapView support
- Feature request - allow to use UITableViewCell with custom style
- Swift Package Manager: reusable deployment target warning HOT 3
- SPM xibs (Bundle.module) HOT 1
- Xcode 12.5 warnings HOT 2
- Swift tools version update too high, lower version build failed
- UITableViewHeaderFooterView - Warning with NibReusable
- Sure, go ahead!
- ## Summary
- Extension for UICollectionViewCell / UITableViewCell with contentView HOT 6
- Problem while compiling with Carthage HOT 3
- NibReusable should have bundle as an optional parameter HOT 5
- Swift 5 Support? HOT 2
- Undefined symbols when compiling for unit tests HOT 1
- Xcode 11 beta 4 compiler error HOT 1
- is there a way to override sceneStoryboard for StoryboardSceneBased HOT 2
- Swift Package Manager HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reusable.