簡體   English   中英

從核心數據中刪除項目

[英]Delete item from core data

我有一個功能,可以返回一些字符串

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)")
    }
}

正如您在找到每個字符串(它是一個URL)后在注釋中看到的那樣,我需要能夠處理它,然后將其刪除。

我可以處理我所擁有的一切,我只是不知道該如何去從核心數據中刪除對象,有人可以給我一些啟發嗎?

意識到我的錯誤,我需要做

context = getContext()

然后我就可以做

context.delete(urls)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM