swift - xcode 6 中的代码不再适用于 xcode 6.3.1

标签 swift xcode6.3.1

在删除 UItableview 中的单元格值之前,我使用了以下代码,它可以正常工作......但现在它给我一个错误。错误:无法使用类型为“(NSManagedObject)”的参数列表调用“deletedObjects” 在以下行中:

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

如何解决这个问题? 函数中涉及的代码:

     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()

最佳答案

删除托管对象是使用 context.deleteObject(anObject) 完成的。试试这个:

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

关于swift - xcode 6 中的代码不再适用于 xcode 6.3.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30421473/

相关文章:

xcode - “stdarg.h”文件未找到错误

ios - 使用数组将值传递给 SWIFT 中的 TIMER

swift - 如何 : Run the . 超时操作符每次呈现 View Controller 仅一次

ios - 从 ARReferenceImage 获取 UIImage 或 CIImage

ios - iOS 8.4 设备出现开发人员磁盘镜像无法安装错误 - 不合格设备部分

ios - 如何快速返回带有参数的先前 View Controller

ios - 如何使用swift将Json作为参数发送到url中

swift - 如何为 UITableViewCell TextView 对象实现实时字数统计?

ios - 属性 'self.*' 未在 super.init 调用时初始化