Wednesday, June 1, 2022 [Tweets] [Favorites]

Safer SwiftUI View Modifiers

Marco Eidinger:

Despite the missing qualifier, the code compiles because padding() gets treated as self.padding(). During runtime, that leads to an infinitely recursive View => stack overflow 💥

I did not find a technique to detect the mistake of a missing dot when using standard SwiftUI view modifiers[…]

But for custom view modifiers there is a simple way. We can use the Swift attribute @warn_unqualified_access to warn us in Xcode :)

Update (2022-06-02): See also: Helge Heß.


Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment