0
0
iOS Swiftmobile~10 mins

SecureField for passwords in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a secure password input field using SwiftUI.

iOS Swift
SecureField("Enter password", text: $[1])
Drag options to blanks, or click blank then click option'
Aemail
Busername
Ctext
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that does not hold the password text.
Forgetting to use the $ sign for binding.
2fill in blank
medium

Complete the code to declare a state variable for the password in SwiftUI.

iOS Swift
@State private var [1] = ""
Drag options to blanks, or click blank then click option'
Ausername
Bpassword
Cemail
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name unrelated to password.
Not declaring the variable as @State.
3fill in blank
hard

Fix the error in the SecureField declaration by completing the code.

iOS Swift
SecureField("Password", text: [1])
Drag options to blanks, or click blank then click option'
A$password
Bpassword
C&password
D*password
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ sign causes a type mismatch error.
Using incorrect symbols like & or *.
4fill in blank
hard

Fill both blanks to create a SwiftUI view with a SecureField and a Text label showing password length.

iOS Swift
struct ContentView: View {
  @State private var [1] = ""
  var body: some View {
    VStack {
      SecureField("Password", text: $[2])
      Text("Length: \([1].count)")
    }
  }
}
Drag options to blanks, or click blank then click option'
Apassword
Busername
Cemail
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the two blanks.
Forgetting the $ sign in the SecureField binding.
5fill in blank
hard

Fill all three blanks to create a SwiftUI view with a SecureField, a Text label showing password length, and a Button to clear the password.

iOS Swift
struct ContentView: View {
  @State private var [1] = ""
  var body: some View {
    VStack {
      SecureField("Password", text: $[2])
      Text("Length: \([2].count)")
      Button("Clear") {
        [3] = ""
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Apassword
Busername
Cemail
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the blanks.
Forgetting to use $ in the SecureField binding.