Updated for Xcode 12.0
New in iOS 14
SwiftUI lets us mark text as a placeholder in our view, meaning that it gets rendered but masked out with gray to show it isn’t final content. This is provided through the redacted(reason:)
modifier, which replaces the isPlaceholder()
modifier they demonstrated at WWDC20.
Here’s how it looks in code:
Text("This is placeholder text")
.redacted(reason: .placeholder)
You can redact several things in your view at once, just by using redacted(reason:)
on a container, like this:
VStack {
Text("This is placeholder text")
Text("And so is this")
}
.redacted(reason: .placeholder)
Apple has said that redaction is an additive process, meaning that if you add redaction reasons to both a parent and a child then they will combine. Right now there’s only .placeholder
, but perhaps we’ll see pixellation or similar in the future?
You can also query any redaction reasons passed in from the environment like this:
@Environment(\.redactionReasons) var redactionReasons
At this time you can’t redact images, which is a shame – hopefully this will appear in a future beta.
SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.