user5684778
user5684778

Reputation:

Swift: Hide a View Controller after first time use

In swift I am making a app where it asks for a code before going to the actual app. I only want this to be showed once. How do I have this page only showed the first time then they enter the code and they only have to do this once then when they use the app again they don't need to enter a code. Thanks.

Upvotes: 0

Views: 509

Answers (1)

paulvs
paulvs

Reputation: 12053

Your best shot is NSUserDefaults. Save a flag (a boolean) in NSUserDefaults to indicate whether it is the first time the user has opened the app.

let userDefaults = NSUserDefaults.standardUserDefaults()
if userDefaults.valueForKey("IS_FIRST_TIME") as? Bool != nil {
    // First time, do something...
    // ...
    // ...
    // Now, save a flag to indicate that this was the first time.
    userDefaults.setValue(true, forKey: "IS_FIRST_TIME")
    userDefaults.synchronize()  // Needed to save the new value.
}

Upvotes: 1

Related Questions