Check data exist before saving in coredata -Swift

核能气质少年 提交于 2019-12-02 09:26:15

First you create a User object in your managed context before calling someEntityExists so most likely this object will be included in the fetch even if it hasn't been saved yet.

Call someEntityExists before even creating a new user entity to see if you should proceed or not

func saveUserInfo(detail:[String:Any])-> Bool {
    if someEntityExists(id: detail["email"] , entityName: "User", type: "String", fieldName: "email") {
        print("Data is already present")
         return false
    }
    //else create and save new user
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!