Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 从核心数据中删除项目_Swift_Xcode_Core Data_Swift3 - Fatal编程技术网

Swift 从核心数据中删除项目

Swift 从核心数据中删除项目,swift,xcode,core-data,swift3,Swift,Xcode,Core Data,Swift3,我有一个函数可以返回一些字符串 func getURLsToSend () { //create a fetch request, telling it about the entity let fetchRequest: NSFetchRequest<URLsToSend> = URLsToSend.fetchRequest() do { //Get results let searchResults = try getCo

我有一个函数可以返回一些字符串

func getURLsToSend () {
    //create a fetch request, telling it about the entity
    let fetchRequest: NSFetchRequest<URLsToSend> = URLsToSend.fetchRequest()

    do {
        //Get results
        let searchResults = try getContext().fetch(fetchRequest)

        //You need to convert to NSManagedObject to use 'for' loops
        for urls in searchResults as [NSManagedObject] {
            //get the Key Value pairs (although there may be a better way to do that...
            print("\(urls.value(forKey: "url"))")

            //Process URL

            //Delete from Core Data

        }
    } catch {
        print("Error with request: \(error)")
    }
}
func getURLsToSend(){
//创建一个获取请求,告诉它有关实体的信息
let fetchRequest:NSFetchRequest=URLsToSend.fetchRequest()
做{
//取得成果
让searchResults=try getContext().fetch(fetchRequest)
//您需要转换为NSManagedObject才能使用“for”循环
搜索结果中的URL为[NSManagedObject]{
//获取键值对(尽管可能有更好的方法。。。
打印(\(url.value(forKey:url)))
//进程URL
//从核心数据中删除
}
}抓住{
打印(“请求错误:\(错误)”)
}
}
正如您在我找到每个字符串(它是一个url)后的注释中所看到的,我需要能够处理它,然后删除它


我可以处理我所拥有的一切,这很好,我只是不知道如何从核心数据中删除对象。有人能帮我解释一下吗?

意识到我的错误,我需要这样做

context = getContext()
然后我就可以简单地

context.delete(urls)