stephan-tolksdorf / STULabel

A faster and more flexible label view for iOS
Other
121 stars 28 forks source link

Accessing UIScreen.mainScreen in +load results in deadlock while injecting test bundle in Xcode 16 #56

Open macdrevx opened 3 months ago

macdrevx commented 3 months ago

Also filed with Apple as FB14703057 (Deadlock in UIKit while injecting test bundle).

Steps to repro:

  1. Create a new iOS project and install STULabel
  2. Open the workspace with Xcode 16 beta 5
  3. Run the unit tests

Actual behavior:

Tests fail to launch due to deadlock

Expected behavior:

Tests run

--

Deadlock occurs inside of the UIScreen.mainScreen access initiated by +load added in the category on UIScreen.

macdrevx commented 3 months ago

I shared this issue on the Apple Dev Forums: https://developer.apple.com/forums/thread/762078

The recommendation is that we should update this to avoid using UIKit prior to main, which implies not using it in +load.

nolanw commented 3 months ago

Here's my fix: https://github.com/happybits/STULabel/blob/eded97a3db8e4b104848aebe33c8e9121ab174d1/STULabel/STUMainScreenProperties.m#L60 I lazy-load on first access of the exported stu_mainScreen…() functions, with a main thread check to avoid deadlock.

If that solution looks appealing then I'd happily open a PR, just let me know.

macdrevx commented 3 months ago

sounds promising. could you go ahead and open the PR so we can see the diff more easily?

nolanw commented 3 months ago

@macdrevx done!

stephan-tolksdorf commented 3 months ago

@macdrevx Thank you for reporting this issue!

Did you already get any reply from Apple on the feedback issue, other than the forum reply?

Are you aware of any documentation implying that UIKit methods can't be called prior to main?

macdrevx commented 3 months ago

@stephan-tolksdorf the reply on the forums is the only one I received. I'm not aware of any statement in the docs about using UIKit prior to main.

macdrevx commented 3 months ago

@stephan-tolksdorf looks like you received a reply from Apple on the forums post: https://developer.apple.com/forums//thread/762078?answerId=802399022#802399022