'init(traitsFrom:)' was deprecated in iOS 17.0, How do I use the new UITraitCollection.init(mutations:)?

3 weeks ago 27
ARTICLE AD BOX

I am using this file from swift-snapshot-testing library. After updating my project to iOS 26, I need to fix all the warnings. But I am not sure how to fix this one:

'init(traitsFrom:)' was deprecated in iOS 17.0: Use UITraitCollection.init(mutations:) and UITraitCollection.modifyingTraits(_:) to create and modify trait collections

This occurs in:

let traits = UITraitCollection(traitsFrom: [config.traits, traits])

from line 921 of the View.swift file which is linked.

One solution could be to explicitly override all traits but it does not feel like a good or smart solution. Can anyone help me figure this out?

Read Entire Article