[iOS, SwiftUI] Privacy View in SwiftUI (with PrivacySensitive and Redacted)

less than 1 minute read

PrivacySensitive

struct BankAccountView: View {
    var body: some View {
        VStack {
            Text("Account #")

            Text(accountNumber)
                .font(.headline)
                .privacySensitive() // Hide only the account number.
        }
    }
}

Redacted

unredacted redacted
unredacted redacted
struct BankAccountView: View {
    var body: some View {
        VStack {
            Image(systemName: "banknote")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 100)

            Text("Account #")
                .unredacted() // show account text

            Text("1234567890")
                .font(.headline)
        }
        .redacted(reason: .placeholder)
    }
}

Privacy Redaction

struct BankingContentView: View {
   @Environment(.redactionReasons) var redactionReasons

   var body: some View {
       if redactionReasons.contains(.privacy) {
           FullAppCover()
       } else {
           AppContent()
       }
   }
}

Leave a comment