iOS

Rea Rahhal
PRO
Rea Rahhal
Pro Student 1,042 Points

I need a way to verify that each username is unique in a registration form using core Data.How can this be done?

This is the code I wrote after successfully creating the context":

    let newUser = NSEntityDescription.insertNewObject(forEntityName: "User", into: context) as NSManagedObject
    newUser.setValue(usernamefield.text, forKey: "username")
    newUser.setValue(passwordfield.text, forKey: "password")
    newUser.setValue(date1, forKey: "dateofbirth")
    newUser.setValue(confirmfield.text, forKey: "confirmpassword")
    newUser.setValue(genderfield.text, forKey: "gender")
    newUser.setValue(cityfield.text, forKey: "city")



    do {
        try context.save()
    } catch {}
    print(newUser)
    print("user Saved.")