Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    Is it too late to start learning AI and machine learning in my 30s or 40s?

    April 8, 2026

    The next chapter of Cisco and Nutanix: Building flexible infrastructure for the modern era

    April 8, 2026

    Pittcon Announces 2025 Nobel Laureate, Dr. Omar Yaghi, as Wallace H. Coulter Keynote Lecturer

    April 8, 2026
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»swift – CloudKit records not deleted when removed from iOS app
    iOS Development

    swift – CloudKit records not deleted when removed from iOS app

    big tee tech hubBy big tee tech hubFebruary 19, 2026012 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    swift – CloudKit records not deleted when removed from iOS app
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    For an unknown reason, when I delete a record in my app, the CloudKit record does not delete. So the next time the app runs, the “deleted” records come back.

    I add the records as follows:

    func addReadingListBook (book: NYTBook, list: ReadingList) {
        //set it
        var bookToAdd = RLBook(nytBook: book)!
        let parentReference = CKRecord.Reference(recordID: list.recordId!, action: .none)
        bookToAdd.parentReference = parentReference //needed for query
        bookToAdd.record.parent = parentReference //needed for sharing
        myReadingListBooksDictionary[book.primaryIsbn13] = bookToAdd
        
        Task {
            do {
                // Save the RLBook record first
                let savedBookRecord = try await db.save(bookToAdd.record)
                
                // Persist related buy links as child records in CloudKit (if any)
                if let links = book.buyLinks, !links.isEmpty {
                    var buyLinkRecords: [CKRecord] = []
                    for link in links {
                        let buyLinkRecordID = CKRecord.ID(zoneID: savedBookRecord.recordID.zoneID)
                        let buyLinkRecord = CKRecord(recordType: "BuyLink", recordID: buyLinkRecordID)
                        buyLinkRecord["parentReference"] = CKRecord.Reference(recordID: savedBookRecord.recordID, action: .deleteSelf)
                        buyLinkRecord["bookIsbn13"] = book.primaryIsbn13
                        buyLinkRecord["name"] = link.name
                        buyLinkRecord["url"] = link.url
                        buyLinkRecords.append(buyLinkRecord)
                    }
                    if !buyLinkRecords.isEmpty {
                        _ = try await db.modifyRecords(saving: buyLinkRecords, deleting: [])
                    }
                }
            } catch {
                Logger.errorLog.error("\(error.localizedDescription)")
            }
        }
    }
    

    I delete the record like this:

    func removeReadingListBook (book: RLBook) {
        myReadingListBooksDictionary.removeValue (forKey: book.primaryIsbn13)
        Task {
            do {
                // Delete related BuyLink records for this book
                let parentRef = CKRecord.Reference(recordID: book.record.recordID, action: .deleteSelf)
                let linkPredicate = NSPredicate(format: "parentReference == %@", parentRef)
                let linkQuery = CKQuery(recordType: "BuyLink", predicate: linkPredicate)
                let linkResult = try await db.records(matching: linkQuery, inZoneWith: book.record.recordID.zoneID)
                let linkRecordIDs: [CKRecord.ID] = linkResult.matchResults.compactMap { try? $0.1.get().recordID }
                if !linkRecordIDs.isEmpty {
                    _ = try await db.modifyRecords(saving: [], deleting: linkRecordIDs)
                }
                
                // Now delete the book record itself
                try await db.deleteRecord(withID: book.record.recordID)
                
            } catch {
                Logger.errorLog.error("\(error.localizedDescription)")
            }
        }
    }
    

    I have checked role permissions and everything else I can think of or find on the internet. Any help would be appreciated.



    Source link

    app CloudKit deleted iOS Records removed Swift
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    ios – What is the most dependable / safest way to make sure the model updates after deleting an item in SwiftData / CloudKit?

    April 8, 2026

    ios – “Use of private header from outside its module:” in a Cocoapods dependency in an Xcode project

    April 7, 2026

    bluetooth lowenergy – Why does my BLE peripheral disappear from my app’s scanning menu after first scanning on iOS?

    April 6, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Is it too late to start learning AI and machine learning in my 30s or 40s?

    April 8, 2026

    The next chapter of Cisco and Nutanix: Building flexible infrastructure for the modern era

    April 8, 2026

    Pittcon Announces 2025 Nobel Laureate, Dr. Omar Yaghi, as Wallace H. Coulter Keynote Lecturer

    April 8, 2026

    ios – What is the most dependable / safest way to make sure the model updates after deleting an item in SwiftData / CloudKit?

    April 8, 2026
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    Is it too late to start learning AI and machine learning in my 30s or 40s?

    April 8, 2026

    The next chapter of Cisco and Nutanix: Building flexible infrastructure for the modern era

    April 8, 2026

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2026 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.