I have the following two methods:
func isAuthenticated() -> Bool {
var currentUser: CurrentUser? = self.getCurrentUser()
if currentUser == nil {
return false
}
self.token = getUserToken(currentUser!.username)
if self.token == nil {
return false
}
if !tokenIsValidForUser(self.token!, user: currentUser!) {
return false
}
return true
}
func tokenIsValidForUser(token: AuthenticationToken, user: UserObject) -> Bool {
if token.username != user.username {
return false
}
return true
}
When I call isAuthenticated()
, it fails on the first line of tokenIsValidForUser()
with EXC_BAD_ACCESS
, apparently on the CurrentUser object.
My understanding si that you get this kind of error when the object no longer exists, but I cannot understand why this would be the case.
The object type CurrentUser is declared as:
protocol UserObject {
var username: String { get set }
}
class CurrentUser: NSManagedObject, UserObject {
@NSManaged var username: String
}