Hey @marthinfreij ,
JP here, maintainer of contentful.swift and contentful-persistence.swift. You should be able to leverage the fallback chain when using the Contentul Swift stack, but things get a little trickier with persistence.
The /sync endpoint always sends content for all locales, so in order to take advantage of the Contentful fallback locale logic, this logic must be implemented client-side. Luckily, the SDK does implement it. However, since CoreData doesn’t allow any dictionary properties on your types, we create a separate entity for each locale in your space to save localized data. If you have 4 locales set up in your space, there will be 4 CoreData entities per asset. These 4 entities would all have the same identifier, so to uniquely identify each, the
Persistable protocol requires that you add an
@NSManaged var localeCode: String to your
NSManagedObject subclasses. You must init your sync manager with a localization scheme like so in order for entities to be saved to CoreData for each locale.
let syncManager = SynchronizationManager(client: client, localizationScheme: .all)
Additionally, you will have to specify a locale when fetching from CoreData. The localized asset that is retrieved in this manner will have values in the fallback locale code if there was is content in the
let assetId = "3Ck6MRrAJ2CaiasGKqeyao"
let assets: [Asset] = try self.store.fetchAll(type: Asset.self, predicate: NSPredicate(format: "id == '\(assetId)' AND localeCode == 'es-MX'"))
I hope that helps!