There is a view with a textField . It is necessary to write down the value entered into it and compare it with the value of another textField from another view . It is desirable to record at all times, and not at the time of the program.

As I understand it, for these purposes you need to raise the database and fasten the view to it?

  • Listen, you would answer the last 8 questions would take - Max Mikheyenko
  • How to take them? - Igor Zexyy
  • click the check mark next to the answer you liked - Max Mikheyenko
  • and the second account? (as I understand it, Igor Ivanov is you too) - Max Mikheyenko
  • Yes. There did too! - Igor Zexyy

2 answers 2

Below is an example of a program using the UserDefaults repository.

 import UIKit class ViewController: UIViewController { let kSomeKey = "SomeKey" @IBOutlet weak var textField1: UITextField! @IBOutlet weak var textField2: UITextField! @IBOutlet weak var lblResult: UILabel! // сохраняем текст, введеный в textField1, "на все время" @IBAction func btnSaveAction(_ sender: Any) { let text1 = textField1.text let userDefaults = UserDefaults.standard userDefaults.set(text1, forKey: kSomeKey) userDefaults.synchronize() } // считываем текст, который был введен в textField1 и сохранен сейчас // или в прошлом сеансе работы программы, и сравниваем его с текстом в textField2, находящемся в другом view @IBAction func btnCompareAction(_ sender: Any) { let userDefaults = UserDefaults.standard let text1 = userDefaults.string(forKey: kSomeKey)! let text2 = textField2.text! if text1 == text2 { lblResult.text = "Результат: значение, сохраненное ранее в textField1 (\(text1)) равно значению в textField2 (\(text2))" } else { lblResult.text = "Результат: значение, сохраненное ранее в textField1 (\(text1)) не равно значению в textField2 (\(text2))" } } } 

screenshot

    Yes, if you need to save a lot of data, then you need to use a database. You can use UserDefaults to save data for a specific key. UserDefaults more about UserDefaults in the UserDefaults documentation .

    It all depends on what you need to do.