[Swift] Use UserDefaults to save data in the app

What are UserDefaults

You can save the data in the app as the title says. In PHP, unlike this session, it remains semi-permanent unless you delete the app from your device. When I started developing apps from web development, I felt comfortable thinking, "Well, I don't have to use a database even in this case."


UserDefaults.standard.set(Variables and things you want to save, forKey:String)

Take out

if UserDefaults.standard.object(forKey:String) != nil {
    //If the key is not empty, put it in a variable
variable= UserDefaults.standard.object(forKey:String)

As mentioned above, the saved data will be displayed properly even if the app is closed and restarted. Deep emotion!

Recommended Posts

[Swift] Use UserDefaults to save data in the app
How to add sound in the app (swift)
[Swift] How to use UserDefaults
Use collection_select to pull down the data stored in Active_Hash
Shorten the UUID to base64 in Swift.
How to overwrite Firebase data in Swift
Is the Swift Xcode 12, New Project, App, Use Core Data code wrong?
Change the save destination of the image to S3 in the Rails app. Part 2
[Swift] How to link the app with Firebase
[Swift] Use Swity JSON to easily get information from JSON data of the fortune-telling API
[Swift] How to display the entered characters in Widget via UserDefaults when using WidgetKit
How to use Swift UIScrollView
How to use the getter / setter method (in object orientation)
[App groups] What to check when UserDefaults data is inaccessible
How to transition from the [Swift5] app to the iPhone settings screen
How to use JSON data in WebSocket communication (Java, JavaScript)
How to create a placeholder part to use in the IN clause
How to use the same Mapper class in multiple data sources with Spring Boot + MyBatis
How to use the link_to method
How to use Lombok in Spring
How to use the include? method
How to use the form_with method
I want to create a chat screen for the Swift chat app!
Pass the i18n locale to JavaScript
How to use Spring Data JDBC
[Swift] How to display when the quiz app answers correctly [Beginner]
I tried to sort the data in descending order, ascending order / Rails
[Swift] Another way to use Result?
How to use the wrapper class
[Swift 5] Processing and precautions for transitioning to the iOS settings app
Use the Findbugs plugin in Eclipse
[Swift] How to use SwiftLint (cocoapods)
[Swift] How to use Unwind segue
How to use InjectorHolder in OpenAM
How to use classes in Java?
I want to remove the top margin in Grouped UITableView (swift)
Show all data stored in UserDefaults
[Swift] How to pass the Label value in the selected collectionViewCell to the destination TextField
Use Timecop in Rails web app to travel time on your browser
Best practice to change settings for each environment in iOS app (Swift)
How to change the maximum and maximum number of POST data in Spark
[Rails] Use devise to get information about the currently logged in user
I tried to make full use of the CPU core in Ruby
To you who were told "Don't use Stream API" in the field
[Swift] How to set an image in the background without using UIImageView.
[Rails] How to apply the CSS used in the main app with Administrate
Is it possible to put the library (aar) in the Android library (aar) and use it?
[Swift] Copy the character string to the clipboard
[swift5] How to specify color in hexadecimal
Multilingual Locale in Java How to use Locale
How to change app name in rails
How to get date data in Ruby
[Java] How to use the File class
How to use custom helpers in rails
Java reference to understand in the figure
[Java] How to use the hasNext function
How to use named volume in docker-compose.yml
[Java] How to use the HashMap class
[Rails] How to use the map method
[Java] How to use the toString () method
[Swift] How to fix Label in UIPickerView