vtourraine / AcknowList

Acknowledgements screen displaying a list of licenses, for example from CocoaPods and Swift Package Manager dependencies.
MIT License
784 stars 59 forks source link

Fix the crash on iOS 15 using Xcode 13 RC #89 #90

Closed psalzAppDev closed 2 years ago

psalzAppDev commented 3 years ago

I described my changes in detail in https://github.com/vtourraine/AcknowList/issues/89.

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

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 is 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.

I fixed the problem, but it is hacky and breaks the standard initializer, so all projects using it have to be updated slightly:

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.

vtourraine commented 3 years ago

Alright, I’ve just published a new version, 2.0.2, that rolls back the Objective-C compatibility (we’ll try to find a nicer solution to bring it back with a later version). I hope that completely fixes the Xcode 13 issue.

lukemmtt commented 3 years ago

I'm still getting a crash after presenting Acknowlist. It was working fine in iOS 14. I'm using Xcode 13 final & iOS 15 final.

vtourraine commented 3 years ago

@lukemmtt Thanks for the feedback. I’ve just tried with the latest Xcode release, but I can no longer see the crash. Could you share the piece of code you use to present/configure your controller?

lukemmtt commented 3 years ago

2.0.3 fixed the issue for me. Thanks for creating this great little tool and for fixing the Xcode 13 issues so promptly!

vtourraine commented 3 years ago

@lukemmtt Good to hear, thanks for the confirmation 👍