In my swift code below the goal is to use func savz to save that data into core data but I am getting a compiler issue stating result of call to saveObject is never used. I dont know how I can get it into a state where it can be used to saved the data into core data.
class ViewController: UIViewController {
@objc func savez() {
CoredataHandler.saveObject(username: "Yahs", password: "213", bool: false)
}
}
class CoredataHandler : NSManagedObject {
private class func getContext() -> NSManagedObjectContext {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
return appDelegate.persistentContainer.viewContext
}
class func saveObject(username: String,password: String,bool: DarwinBoolean) -> Bool{
let context = getContext()
let entity = NSEntityDescription.entity(forEntityName: "User", in: context)
let managedObject = NSManagedObject(entity: entity!, insertInto: context)
managedObject.setValue(username, forKey: "username")
managedObject.setValue(password, forKey: "password")
managedObject.setValue(bool, forKey: "bool")
do {
try context.save()
return true
} catch{
return false
}
}
}