Chapter 21: Using property wrappers

Hi,

In chapter 21 you say:

SwiftUI uses property wrappers extensively to let us assign extra functionality to our variables, structs and classes.

I learned to my cost that SwiftUI and property wrappers have unexpected traps.

I have a SwiftUI app that sends some of its work to Metal to take advantage of parallelism. A number of buffers are involved holding arrays of [Int32] and [Float]. It seemed like a good idea to invent a property wrapper to handle all the related buffer stuff (pointers, capacity, stride, loading and recovering data and so on). It worked just fine.

Then I decided I’d compare my fantastic parallel app with a slow old serial version and it turns out it was much slower!!!

The problem seems to be that every refresh of the screen recopies the arrays. Here’s a page that discusses it. (It’s a little over my head).

A massive oversight by Apple I presume.