1

before this to delete a cell value in UItableview i use the following code and it works as it should .... but now it give me an error. THE ERROR: Cannot invoke 'deletedObjects' with an argument list of type '(NSManagedObject)' on the following line:

context.deletedObjects(results[indexPath.row] as NSManagedObject)

How to fix this? The codes in the function involved:

     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Default")
            var appDel = (UIApplication.sharedApplication().delegate as! AppDelegate)
            var context = appDel.managedObjectContext
            var request = NSFetchRequest(entityName: "UserCholesterol")
            request.returnsObjectsAsFaults = false
var results: NSArray = context!.executeFetchRequest(request, error: nil)!
        context.deletedObjects(results[indexPath.row] as NSManagedObject)

        context!.save(nil)
        totalEntries = totalEntries - 1
        tblLog.reloadData()
  • I very much doubt that `context.deletedObjects()` worked in previous versions of Xcode. It may have compiled, but it did not delete any objects in any Xcode/Swift version. – Martin R May 24 '15 at 09:08

2 Answers2

0

Deleting a managed object is done with context.deleteObject(anObject). Try this:

context.deleteObject(results[indexPath.row] as NSManagedObject)
Bannings
  • 10,376
  • 7
  • 44
  • 54
0

deletedObjects is just a property of NSManagedObjectContext,not a method.But there is a method called - deleteObject:.

Try to replace to this line of code:

context.deleteObject(results[indexPath.row] as! NSManagedObject) // in Xcode 6.3 and above,you have to add ! after `as` keyword.
tounaobun
  • 14,570
  • 9
  • 53
  • 75
  • thanks guys you save my day .. sometime i just want to rollback to the previous version of xcode . i type context!.deleteObject(results[indexPath.row] as! NSManagedObject) and all erros gone. I'm very sceptical to upgrade to 6.3.2 ... – Hasnah Ngah May 24 '15 at 08:54