Closed jminutaglio closed 3 years ago
It is probably a bug that will be fixed in later Xcode versions - some problems with the initializers not visible to objc. However, for now, I got it resolved using this: https://stackoverflow.com/questions/69092599/xcode-13-beta-5-error-uiviewcontroller-is-missing-its-initial-trait-collection
I will try to put this into a PR
Ok, so I tried my solution, but it turned out that your last convenience initializer that finally calls super.init(style:) uses an array of Acknow, which is a struct. Therefore, this initializer cannot be exposed to @objc
.
The solution would be to expose all convenience initializers to @objc
and then overriding init(style:)
, like this:
/**
Bugfix for [Issue #89](https://github.com/vtourraine/AcknowList/issues/89).
On iOS 15 using Xcode 13 RC, the initializer will crash unless this one is overridden.
Solution taken from [StackOverflow](https://stackoverflow.com/questions/69092599/xcode-13-beta-5-error-uiviewcontroller-is-missing-its-initial-trait-collection)
*/
public override init(style: UITableView.Style) {
self.acknowledgements = []
super.init(style: style)
}
And then calling self.init(style: style)
in the convenience initializer instead of super.init(style: style)
:
@objc public convenience init(acknowledgements: [Acknow], style: UITableView.Style = .grouped) {
self.init(style: style)
self.acknowledgements = acknowledgements
self.title = AcknowLocalization.localizedTitle()
}
It seems to be your only solution for now is to remove the above convenience initializer, which means acknowledgements have to be set after initialization. Or hope that Apple fixes this annoying bug anytime soon.
Something really hacky might work too:
Duplicate Acknow
as a class inheriting from NSObject
, thus exposing it to @objc
. Then replace the struct Acknow
array in the initializer with the class Acknow
array and create a struct Acknow
array by copying the values.
Something like this:
@objc public class AcknowC: NSObject {
// Duplicate everything as in struct Acknow
}
...
@objc public convenience init(acknowledgements: [AcknowC], style: UITableView.Style = .grouped) {
self.init(style: style)
self.acknowledgements = acknowledgements.map {
Acknow(title: $0.title, string: $0.string, license: $0.license)
}
self.title = AcknowLocalization.localizedTitle()
}
So this actually works. I'll create a PR for you to test and then you can decide whether you want this hacky and breaking change or wait until Apple fixes this bug (hopefully...)
@psalzAppDev - used your code/fork and confirmed it works here also. TY so much! iOS 15 is coming bugs or not! :)
Thank you so much for reporting this issue, and for preparing the pull request!
I’m not sure we should merge it as-is, though. Is it really just a bug, or just how the latest Swift compiler works? I would love to better understand the issue before touching the initializers interface. Any indication about what is going on exactly?
But in the meantime, I’m glad we have your workaround for folks who would need it.
Thank you so much for reporting this issue, and for preparing the pull request!
I’m not sure we should merge it as-is, though. Is it really just a bug, or just how the latest Swift compiler works? I would love to better understand the issue before touching the initializers interface. Any indication about what is going on exactly?
But in the meantime, I’m glad we have your workaround for folks who would need it.
I agree, this is a messy fix and I hope that this is an internal bug that will soon be fixed. There is not much information around about it though. I can't believe that this behavior is intended.
On the downside, anyone who uses your framework will notice that the app crashes on iOS 15. So hopefully they find their way to this thread and can decide whether to use my PR for now to keep their app working. That's what I did when I noticed that my app crashed on my iOS15 test device.
When new Xcode versions arrive, I will test for this bug and report back to you.
I’m not sure we should merge it as-is, though. Is it really just a bug, or just how the latest Swift compiler works? I would love to better understand the issue before touching the initializers interface. Any indication about what is going on exactly?
My $0.02 - this will be the shipping iOS 15 and the impact is that AcknowList will fail on open every time - so the impact to AcknowList is as major as it gets, starting next week when iOS 15 drops. I'd implement the workaround unless & until Apple's build allows the current initializer code to function without failure. Considering the length of the iOS 15 beta I'd suggest it won't be anytime soon... :/
@jminutaglio Agreed, we should address that as soon as possible.
I have found a different solution, though. The problem somehow comes from the interoperability between Swift and Objective-C code. If we remove the @objc
annotations from the initializers, there’s no more crash. I would also mean that the library would no longer be usable from Objective-C code. That’s bad, but I think I would rather do that, instead of adding all the extra code to dance around the issue.
What do you think?
@vtourraine - makes sense to me. I'd guess most projects have moved from Obj-C to Swift at this point, so the impact to folks using AcknowList may be minor/none...
@vtourraine - AcknowList 2.0.2 is still throwing the assertion failure on iOS 15 - FYI.
:(
Hum, it gets weirder indeed. The crash is fixed for the “AcknowExampleManual” project, but not for the “AcknowExampleCocoaPods”. 😞 Looking into it...
Alright, I reimplemented the AcknowListViewController
default initializer, and it seems to really fix this issue. I’ve released it as version 2.0.3
. Please check it out, and let me know if that works for you.
@vtourraine - looks good here. Confirmed fixed!
TY!
@jminutaglio Glad to hear it, thanks for the feedback 👍
Using:
On Xcode 13 RC (Version 13.0 (13A233)) ->
On Simulator iOS 14.5 -> expected behavior (AcknowList viewController shows)
On Simulator iOS 15.0:
Same codeline, just an error on iOS 15...
Any ideas? ty in advance. AcknowList is awesome btw!