NSView.layer not reliably set in viewDidLoad

Originator:mayoff
Number:rdar://32698202 Date Originated:11-Jun-2017 12:16 AM
Status:CLOSED Resolved:
Product:macOS + SDK Product Version:Version 9.0 beta (9M136h) / 10.13 Beta (17A264c)
Classification:Serious Bug Reproducible:Sometimes
 
Summary:
Dear AppKitterinos,

I have a view in a storyboard. The view’s wantsLayer is true in the View Effects inspector.

When the view controller’s viewDidLoad runs, the view’s layer is usually (but not always) still nil even though the view’s wantsLayer is always true at this point.

The behavior arises because the view sets its layer in its _finishMakingConnections method, and the view controller sends itself viewDidLoad from its own _finishMakingConnections method. Since the _finishMakingConnections messages are sent using -[NSSet makeObjectsPerformSelector:], the order in which the messages are sent is non-deterministic and (probably due to address space layout randomization) indeed varies across executions.

I’ve attached a project that demonstrates the problem. You may need to run the project many times to reproduce the problem. If you’re having trouble reproducing, try changing the objects in the storyboard, adding instance variables to MyView and/or ViewController, or changing the order in which the classes are defined in ViewController.swift.

When the problem occurs, the output of the test project looks like this:

-------- in viewDidLoad() 
view.wantsLayer=true
view.layer=nil ‼️

-------- in viewDidLoad() (after view.wantsLayer = true)
view.wantsLayer=true
view.layer=0x000060800004e7c0
bootstrap_check_in():  (os/kern) unknown error code (44c)

Love,
Rob


Steps to Reproduce:
 

Expected Results:
 

Actual Results:
 

Version:
Version 9.0 beta (9M136h) / 10.13 Beta (17A264c)

Notes:

Comments

Apple Developer Relations Aug 14 2017 We believe this issue has been resolved in the latest macOS 10.13 beta.

Please test with the latest beta. If you still have issues, please update your bug report with any relevant logs or information that could help us investigate.

macOS https://developer.apple.com/download/


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!