Giter VIP home page Giter VIP logo

Comments (5)

tomkowz avatar tomkowz commented on August 11, 2024

Hello @pravking,

You can re-sync the content of the core data by setting sync token to nil and then performing a sync request. Add this method to your codebase.

    /// Resets the sync token and allow for further sync of the content again. Make sure you cleaned up all your
    /// models before resyncing.
    func resetSyncToken(moc: NSManagedObjectContext) {
        let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: String(describing: SyncSpace.self))

        do {
            guard let syncSpace = try moc.fetch(fetchRequest).first as? SyncSpace else { return }
            syncSpace.syncToken = nil

        } catch let error as NSError {
            print(error)
        }
    }

Let me know if that works for you.

from contentful-persistence.swift.

pravking avatar pravking commented on August 11, 2024

Thanks for the solution @tomkowz.

Had to use 'SyncInfo' instead of 'SyncSpace' given in the code snippet to get it working.

from contentful-persistence.swift.

tomkowz avatar tomkowz commented on August 11, 2024

Hmm... Okay, I see the SyncInfo does not expose the syncToken. I think you could then remove the SyncInfo from the store and then re-sync. Removing it from the store will have the same effect like setting it to nil.

    private func deleteSyncInfo() {
        let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "SyncInfo")
        let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)

        do {
            try managedObjectContext.persistentStoreCoordinator?.execute(deleteRequest, with: managedObjectContext)
            try managedObjectContext.save()

        } catch let error as NSError {
            print(error)
        }
    }

Btw. I know ContentfulPersistence just for a bit now but in my demo projects for debugging purposes I am using a custom SyncSpace instead of SyncInfo because of the easy access to the token.

When you switch to use SyncSpace you'll not need to do a delete request because token will be nil anyway.

Let me know if the above work for you.

from contentful-persistence.swift.

pravking avatar pravking commented on August 11, 2024

Thanks @tomkowz removing SyncInfo from store is also working.

Also, is it necessary to clear all the models before re-syncing?
When I tried clearing only the SyncInfo model and then calling sync also the re-syncing is working.

from contentful-persistence.swift.

tomkowz avatar tomkowz commented on August 11, 2024

I don't think this is necessary. If that works for you without removing data then that's fine. That was my advice just to make sure. I think we can close this one then.

from contentful-persistence.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.