I have seen a few articles or video's on iOS 15's new Self._printChanges()
function, but can not find any documentation on it anywhere. Does anyone know where Apple documented this new function? It is pretty obvious how to use it, but I would like to see what more we can do with it and knowing more about it would be helpful. Even Xcode's lookup's yield nothing. Anyone find anything?

- 319
- 3
- 11
-
1If you know the SwiftUI you would really do not need `Self._printChanges()` there is lot of ways to get report on values. So why this is important for you? What is the benefit of `Self._printChanges()` that we could just get from it? – ios coder Nov 05 '21 at 22:02
2 Answers
Unfortunately, _printChanges()
is a private API, which is why it's undocumented. The only reason so many videos and articles referenced it is because an Apple engineer mentioned it during WWDC21. Here's what they said:
It's not technically API-notice the leading underscore — so should only be used in debugging. My one sentence pro-tip is the extent of the docs I'm afraid.
However, Xcode does show a summary when you Option + Click.
Summary
When called within an invocation of body of a view of this type, prints the names of the changed dynamic properties that caused the result of body to need to be refreshed. As well as the physical property names, “@self” is used to mark that the view value itself has changed, and “@identity” to mark that the identity of the view has changed (i.e. that the persistent data associated with the view has been recycled for a new instance of the same type).

- 24,434
- 8
- 68
- 125
-
1I see, thanks for letting me know. I am only using it for DEBUG, but would like to push it into a log output, not just to the console, but it appears its only use case is to output to the console. I was hoping if I could see the docs and other info I would be able to come up with something. I guess we will just have to use it as far as it works for now. Thanks again! – JustMe Nov 05 '21 at 23:12
-
@JustMe np! If you want to save the output to some log, you're probably better off using [`onChanged`](https://developer.apple.com/documentation/swiftui/view/onchange(of:perform:)) on your properties. Also if the answer was helpful, could you click the green checkmark to accept it? – aheze Nov 06 '21 at 05:14