Comments (5)
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.
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.
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.
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.
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)
- [BUG] SynchronizationManager.seedDBFromJSONFiles throwing incorrect invalidFilePath HOT 1
- [Documentation] Missing reference to contentful-utilities HOT 2
- [BUG] Incremental sync issues with 0.17.1 HOT 5
- Changing of handling symbol arrays causes crash while seeding DB HOT 3
- After updating to the latest version of SDK 0.17.4, app crashes while syncing
- Crash on launch; dyld Symbol not found in Swift 5.4 / XCode 12.5 HOT 1
- To One relationship with mapped relationship name results in crash while trying to sync HOT 1
- Crash after mutating model that removes a references within resolveRelationships when cached.
- Sync not removing invalid relationships? HOT 1
- Sync not removing invalid relationships if a full sync is performed
- 'Cannot find 'SyncInfo' in scope' when loaded via SPM HOT 3
- Error When Building contentful-persistence.swift in Cartfile with new version of Swift
- SynchronizationManager.sync() throws JSON Decoding exception
- Update podspec to use contentful 5.0.0 HOT 1
- Property cannot be marked @NSManaged because its type cannot be represented in Objective-C HOT 2
- Use of unresolved identifier 'SyncInfo' HOT 1
- Update podspec HOT 2
- Persisting RichTextDocument HOT 12
- Coredata relationship not getting synced when un-publishing and publishing an entry with reference HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contentful-persistence.swift.