Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The update operation doesn't work #333

Open
wugang8068 opened this issue Jun 4, 2017 · 0 comments
Open

The update operation doesn't work #333

wugang8068 opened this issue Jun 4, 2017 · 0 comments

Comments

@wugang8068
Copy link

wugang8068 commented Jun 4, 2017

What

when I update the entity first it works , but it failed when I update it again with different data;

Context

Here is my code:
// I called flowed function first , and it worked when I restart my app.

static func storeAuth(
        grantType:String,
        clientId:Int16,
        clientSecret:String
        ) -> Bool{
        let auth = self.getUserAuth();
        if auth == nil{
            do{
                try AppUser.db.operation({ (context, save) throws in
                    let auth:UserAuth = try context.new();
                    auth.grantType = grantType;
                    auth.clientId = clientId;
                    auth.clientSecret = clientSecret
                    try context.insert(auth)
                    save()
                })
                return true
            }catch{
                debugPrint(error.localizedDescription)
                return false;
            }
        }else{
            do{
                try AppUser.db.operation({ (context, save) throws in
                    auth?.grantType = grantType;
                    auth?.clientId = clientId;
                    auth?.clientSecret = clientSecret
                    save()
                })
                return true;
            }catch{
                debugPrint(error.localizedDescription)
                return false;
            }
        }
    }

// and I call this function to update it again, but when I restart my app, the updated data was not stored. the data was that updated before;

static func updateAuthToken(expiresIn:Int,
                                refreshToken:String,
                                tokenType:String,
                                accessToken:String){
        let auth = self.getUserAuth();
        if auth != nil{
            do{
                try AppUser.db.operation({ (context, save) throws in
                    auth?.tokenExpiredAt = NSDate().addingSeconds(expiresIn) as NSDate?
                    auth?.refreshToken = refreshToken
                    auth?.tokenType = tokenType
                    auth?.accessToken = accessToken
                    save()
                })
            }catch{
                debugPrint(error.localizedDescription)
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant