0Pricing
SwiftUI Academy · Урок

SecureField для паролей

Скрывайте конфиденциальный ввод с помощью SecureField.

«SecureField для паролей» — бесплатный урок SwiftUI Academy на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения SwiftUI Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс SwiftUI Academy содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

Hiding Sensitive Text

Passwords should never appear on screen as plain letters. SwiftUI gives you SecureField, a text field that masks every character. 🔒

Just Like TextField

A SecureField works exactly like a TextField: a placeholder and a binding. The only difference is the dots shown instead of the real characters.

SecureField("Password", text: $password)

It Still Needs State

Just like before, the typed value lives in a @State string. SecureField reads and writes it through the binding you pass with the $ prefix.

@State private var password = ""

The Real Value Is Yours

The dots are only for display. Your state string holds the actual text, so you can validate or send it even though the screen hides it.

A Bordered Look

Give it the same polish as any field. The textFieldStyle modifier with .roundedBorder makes a clean, tappable password box.

SecureField("Password", text: $password)
  .textFieldStyle(.roundedBorder)

Pairing With Username

A login screen usually stacks a normal TextField for the email above a SecureField for the password, each with its own state.

TextField("Email", text: $email)
SecureField("Password", text: $password)

Helping the System

Add textContentType(.password) so iOS offers saved passwords and Keychain suggestions, making sign-in faster for your users.

SecureField("Password", text: $password)
  .textContentType(.password)

New vs Existing Passwords

On a sign-up screen use .newPassword instead. iOS then suggests a strong, unique password and stores it in the Keychain.

SecureField("New password", text: $pw)
  .textContentType(.newPassword)

Reacting to Submit

SecureField supports onSubmit too. When the user taps return, run your login or move focus to the next field.

SecureField("Password", text: $pw)
  .onSubmit { logIn() }

Privacy by Default

Because the characters are masked, no one glancing at the screen sees the password. SecureField gives you that privacy for free.

Same Skills, Safer Field

Everything you learned about binding text still applies. SecureField is simply the safe choice whenever the input is a secret. ✨

Quick Check

What is the main difference between SecureField and TextField?

Recap

You masked secret input with SecureField, kept the real value in state, and used textContentType to help iOS suggest and save passwords. 🎉

Часто задаваемые вопросы

Урок «SecureField для паролей» бесплатный?

Да — полный текст урока «SecureField для паролей» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс SwiftUI Academy, подпишись на CoddyKit PRO. Курс SwiftUI Academy содержит 4 уроков всего.

Чему я научусь в уроке «SecureField для паролей»?

Скрывайте конфиденциальный ввод с помощью SecureField. Ты практикуешь SwiftUI Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать SwiftUI Academy?

Предыдущий опыт не требуется. SwiftUI Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.

Сколько времени занимает урок «SecureField для паролей»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке SwiftUI Academy?

Да. Каждый урок SwiftUI Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Привязка TextField к состоянию
  2. Типы клавиатуры и заполнители
  3. SecureField для паролей
  4. Проверка ввода в реальном времени
← Назад к SwiftUI Academy