iOS keep user on Keychain sometimes does not work
<p>On <code>func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)</code> I check if user has logged in before as the following:</p>

<pre><code>let user = KeychainManager().getCurrentUser()
if user.isValid() {
    self.redirectToMain()
}
else {
    self.redirectToWelcome()
}
</code></pre>

<p>This is how <code>getCurrentUser()</code> method looks like:</p>

<pre><code>let currentUser = CurrentUser()
currentUser.Id = Int(KeychainWrapper.stringForKey(KeychainKeyConstants.idKeyForKeychain).toNonNullable("0"))
currentUser.email = KeychainWrapper.stringForKey(KeychainKeyConstants.emailKeyForKeychain).toNonNullable("")
// Other properties...
return currentUser
</code></pre>

<p>This is how I save user into Keyhchain:</p>

<pre><code>let currentUser = CurrentUser()
currentUser.Id = loginModel.Id
currentUser.email = loginModel.email
// Some other properties...
KeychainManager().saveCurrentUser(currentUser)
</code></pre>

<p>This is how <code>saveCurrentUser()</code> method looks like:</p>

<pre><code>KeychainWrapper.setObject(user.Id!, forKey: KeychainKeyConstants.idKeyForKeychain)
KeychainWrapper.setString(user.email, forKey: KeychainKeyConstants.emailKeyForKeychain)
// More properties...
</code></pre>

<p>Here is <code>isValid()</code> method of <code>CurrentUser</code>:</p>

<pre><code>if self.Id == nil || self.email.isEmpty /* other properties... */ { return false }
return true
</code></pre>

<p>This logic mostly works but under some circumstances it does not. I, sometimes, surprisingly being redirected to the login page (<code>redirectToWelcome()</code>) even if I am already logged in. Once I encountered that problem while I was debugging the app, the problem was there were some values were not fetched (I didn't have a chance to see which values). I can't reproduce the error, I can't see what causes that problem.</p>

<p>I use <code>KeychainWrapper</code> to access Keychain, here: <code>https://github.com/jrendel/SwiftKeychainWrapper</code></p>

<p>Has anybody got any idea for that? What could possibly may cause that issue?</p>