UserDefaults.standard.string() returns nil

I “inherited” an iOS Xcode Project in Swift. I’ve never programmed in Swift or used Xcode before. I copied the project from one user account to another and checked it into a git repo.

Now I’m araid this (the copying, permissions ?) might be the cause for the App not being able to read its settings properly. Because UserDefaults.standard.string(forKey: “pref_Foo”) returns nil although in the Settings.Bundle’s Root.plist there’s clearly a pref_Foo identifier.
The App has worked before, so I don’t see where this suddenly comes from.
Since I’m not too familiar with XCode all I did up til now was debug into the Application to see that UserDefaults.standard.string(forKey: “pref_Foo”) is nil.

How could I approach this problem?
Thank you!

EDIT: This is part of my code in ViewController.swift

 override func viewDidLoad() {
        super.viewDidLoad()
  loadSettings()

 }

func loadSettings()
{
  if(UserDefaults.standard.object(forKey: "pref_Foo") == nil)
  { 
   printf("Error")
  }
}

You should use below code with validation, first delete app and install again. then use, you will get success.

var UserStatus:String {
    get{
        return UserDefaults.standard.object(forKey: "pref_Foo") as? String ?? "0"
    }
    set(status){
        UserDefaults.standard.set(status, forKey: "pref_Foo")
        UserDefaults.standard.synchronize()
    }
}

Use of code is as below.

if (UserStatus ==  "pref_Foo"){
    self.logoutSuccess()
} else {
    self.loginSuccess()
}

Update or set value is so simple in one line code as given below.

        UserStatus = "pref_Foo"