angelolloqui/AGi18n

iOS 11 - Xcode 9 beta 6

adrienbrunwod opened this issue · 11 comments

Using Xcode 9 beta 6 to build my project (toolchain Swift Development Snapshot 2017-08-21), it stopped working. Text from the storyboards is no longer localized.

I have to download the beta 6 to try this out, but at least in beta 5 (the one I have right now) there is no issue. Have you found the cause?

Seems like the load method is never called and so neither is the awakeFromNibCustom. But if you have it working with the beta 5 it might be some configuration issue on my end.

@angelolloqui I can't figure out what changed. Any idea what configuration might have been impacted when trying the beta?

I'm having similar issue but not always happened. Only happened in a specific flow.

This issue often happened after I opened a WebView with approximate 150MB memory usage in the App, then the Text of UILabel in Xib files would be no longer localized at every page. Not sure this scenario is related to the issue directly or not.

build with Xcode 9 beta 6,7,8 and now using beta 9 the issue is still exist. any idea~?

Thanks.

Just noticed that this issue may be related to Hot-Patch disabled from Apple's notification recently.

Maybe there's a misjudgment by the runtime method "method_exchangeImplementations" which called by a View with running WebView?

extension UILabel {
open override func awakeFromNib() {
super.awakeFromNib()
if let text = self.text, text.count > 0 {
self.text = Bundle.main.localizedString(forKey: text, value: "", table: nil)
}
}
}

That seems to work

The problem with override awakeFromNib in an extension is that it might run into undefined behavior in future versions since overriding into extensions is discouraged. If for example Apple (or a third party sdk) implements that method then yours will not be called (or will be called randomly in exchange of the other).
That is why I decided to go with swizzling, that as far as UIKit runs on objc-runtime should work ok.

Now, seeing that many of you have an issue, we will need to research, but I do not like the fact that it happens after some rare circumstances. It looks like Apple is actually reloading the whole class or doing swizzling themselves (in a wrong way since done properly it could cohexist).

If you want a temporal fix, do what @adrienbrunwod suggested, it should work, but a more consistent solution should be found

I will try to create a branch tomorrow with the overriding in a category so you can at least import that branch while I find proper time to research (or someone else does)

I've done a similar workaround in NSObject+AGi18n file.

Thank you @angelolloqui @adrienbrunwod and maybe the issue I encountered will be gone somehow at official iOS 11 :D

I have added a 0.0.3 version (also to CocoaPods) with the overriding solution. Since it might be temporal, I have included a precompilation header called AGI18N_USE_SWIZZLINGthat when set to 1will use the swizzling again.