Skip to content

Using UserDefaults to save parameters

   

UserDefaults are used to store data that you want to keep even if you drop the app.
It's very simple to use.
In the sample code, the initial value is set with userDefaults.register(defaults: ["KEY_LabelText": "Hello"]] at first.
The .register () is very useful and puts the initial value when there is no data corresponding to the specified key.
Then the label reads the value saved by UserDefault and reflects it in the text of the label.
And when the button is pressed, it updates the value of the userdefaults and label.

alt

  1. Selecting values using the UIPickerView
  2. Repeating at a certain time
  3. Create a collection view with custom layouts
  4. UDP communication in Swift and sending a string
  5. Removing @objc inference warnings when migrating from Swift3 to Swift4
  6. Pinch to zoom in and out on an image with UIScrollView
  7. Removing the back button in UINavigationController.