-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert the Convenience Inits to designated Inits to use them for subclassing. #47
Conversation
Codecov Report
@@ Coverage Diff @@
## master #47 +/- ##
==========================================
- Coverage 57.17% 56.18% -0.99%
==========================================
Files 32 32
Lines 1018 1018
==========================================
- Hits 582 572 -10
- Misses 436 446 +10
Continue to review full report at Codecov.
|
You don't need to change What you can do is provide a subclass that override class MyProvider<Data, View: UIView>: CollectionProvider<Data, View> {
override init(identifier: String? = nil,
dataProvider: DataProvider,
viewProvider: ViewProvider,
layout: Layout = FlowLayout<Data>(),
sizeProvider: @escaping SizeProvider = defaultSizeProvider,
presenter: Presenter? = nil,
willReloadHandler: (() -> Void)? = nil,
didReloadHandler: (() -> Void)? = nil,
tapHandler: TapHandler? = nil) {
super.init(identifier: identifier,
dataProvider: dataProvider,
viewProvider: viewProvider,
layout: layout,
sizeProvider: sizeProvider,
presenter:presenter,
willReloadHandler: willReloadHandler,
didReloadHandler: didReloadHandler,
tapHandler: tapHandler)
}
} Then you can use override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let provider = MyProvider(
data: testData,
viewUpdater: { (view: ContentView, data: OffsetData, at: Int) in
view.populate(data: data)
}
)
provider.layout = OffsetLayout()
provider.sizeProvider = OffsetDataSizeProvider
collectionView.provider = provider
} |
I don’t want to get them for free. I want to use the convenience inits within my own simple init function. But you can’t call a convenience init within a designated custom init of the subclass.
That is not possible. I basically want to reproduce the Reusable Provider of the documentation which is not working. |
I think this kinda make sense. I also felt the need to call one of these convenient initializer in one of my subclass. @jindulys should we consider merging this in? |
willReloadHandler: (() -> Void)? = nil, | ||
didReloadHandler: (() -> Void)? = nil, | ||
tapHandler: TapHandler? = nil) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line
willReloadHandler: (() -> Void)? = nil, | ||
didReloadHandler: (() -> Void)? = nil, | ||
tapHandler: TapHandler? = nil) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been merged I think
Sry i was on holiday and wasn‘t able to correct the code. Will happen in the next days. Sent with GitHawk |
I tried to subclass the CollectionProvider today and got an error that I can't use the convenience Inits (like used in the documentation) for subclassing.
My proposal is to convert the convenience inits to designated inits. Sadly simply removing the convenience mark resulted in an error:
I know that simply duplicating code isn't really helpful so if someone has a better solution to make those Inits subclassable, you'r welcome :)