Comments (10)
Hi @tapwork,
Can you please upgrade to the latest version of contentful.swift (version 0.4.1) and see if you're still having a similar issue?
Decodable is no longer a dependency of Contentful anymore. It has been replaced with ObjectMapper
from contentful.swift.
I even switched to the ContentfulPersistence
and https://github.com/contentful/contentful.swift/releases/tag/0.4.1
But there I get lots of MapError
(throw)
My mapping looks as follows:
synchronizer.mapAssets(to: Asset.self)
synchronizer.map(contentTypeId: "teaser", to: FeedTeaser.self)
I am using all the properties for CoreData I have in the Contentful CMS.
But the mapping issues occur with the following keys:
locale
, contentType.sys.id
, createdAt
, updatedAt
, revision
, message
Those properties are not part of my model. They look more like the sys properties
The mapping for entities itself seems to work.
from contentful.swift.
I was not aware you were using ContentfulPersistence as well. Make sure you have a property on your FeedTeaser
that is exactly like the following:
@NSManaged var id: String?
If you still have trouble, please open a support ticket with support.contentful.com. When doing so, please link this Github issue and mention that the iOS developer sent you to the support channel so that the ticket will be assigned to me by our support team.
Also, send along the following information:
- A copy of your
FeedTeaser
class. - If you are using Cocoapods or Carthage for installation.
- The block of code where you call
sync()
on yourContentfulSynchronizer
instance.
Thanks.
from contentful.swift.
Thanks for your fast answer. We just switched to ContentfulPersistence
I have the id
key as well. But still...I will send a detailed description to support.
But nevertheless how do I get the NSManagedObject
models after fetching entries?
self.client.fetchEntries(matching: ["content_type": contentType.rawValue]) { result in
switch result {
case .success(let arrayResponse):
// how to get the NSManagedObject objects here from arrayResponse
case .error(let error):
completion(.failure(ContentfulResultError.failedResponse(error)))
}
}
There is this arrayResponse
object and it has some internal access to the NSManagedObject
models, but not for us.
I tried it with a NSFetchRequest
directly in the success
case. But I had no luck to get any
from contentful.swift.
Hi @tapwork contentful-persistence.swift is only designed to specifically work with the /sync
endpoint of the Content Delivery API. If you are using the regular /entries
or /assets
endpoints, you must map your entries to NSManagedObject
instances on your own.
In the comment you left above // how to get the NSManagedObject objects here from arrayResponse
, this is the point where you would perform your mapping and save to CoreData.
from contentful.swift.
As an added note, if you are only using these endpoints, the persistence library will be quite useless for you, and you may want to consider pruning it from your project.
from contentful.swift.
is this the proper way to fetch from /sync endpoint?
self.client.fetchEntries(["content_type": contentType.rawValue]).1.next {
print($0)
}
got this from https://www.contentful.com/developers/docs/ios/tutorials/using-delivery-api-with-swift/
or is it just self.synchronizer.sync
? (found this in https://github.com/contentful/product-catalogue-swift/blob/master/Code/DataSource.swift after some investigation)
from contentful.swift.
The correct way to interact with the sync endpoint is indeed the later snippet you posted. It is not necessary to use the persistence library to do this however. You can see the reference documentation for the sync methods on the Client
type of contentful.swift here—as a side note, the reference docs are fully compatible with Xcode's documentation system, so you should be able to navigate through the SDK in Xcode as well.
To properly use contentful-persistence.swift, you would do the following:
self.coreDataStore = CoreDataStore(context: self.managedObjectContext) // You're responsible for creating you managedObjectContext
let synchronizer = ContentfulSynchronizer(client: self.client, persistenceStore: self.coreDataStore)
synchronizer.mapAssets(to: Asset.self)
synchronizer.map(contentTypeId: "teaser", to: FeedTeaser.self)
// Do the sync operation with the API.
synchronizer.sync() { success in
// Now you can fetch from CoreData
let teasers: [FeedTeaser] = self.coreDataStore.fetchAll(type: FeedTeaser.self, predicate: NSPredicate(value: true))
}
from contentful.swift.
thanks for your answer. I tried that with .sync()
but I get some mapping errors with the Asset.
I filed an issue https://support.contentful.com/hc/requests/16663
from contentful.swift.
Fixed in #70
from contentful.swift.
Related Issues (20)
- Xcode 12 build warnings because Contentful.podspec is still using iOS8 HOT 1
- Including .localizeResults(withLocaleCode:) causes decoding to fail due to keyNotFound HOT 1
- completion handler is invoked twice with two different failure results HOT 6
- Initial data sync with Contentful in iOS takes more time when compare with Andoid HOT 4
- Api Reference unreachable HOT 1
- Need to register two or more classes to a single Content Type
- Client is failing to parse Contentful api response HOT 2
- Incremental sync not supported on Preview API
- Contentful API breaks Swift Concurrency by calling completion handlers more than once HOT 4
- Models that conform to Resource and have a member variable named id, breaks resolveLinksArray method
- 1b8b443b61b8b37fafb06c1abad9b6be244c9de9
- The Contentful framework fails to build in XCode Version 14.3.1 HOT 3
- Client.jsonDecoderBuilder is not thread-safe
- import Contentful // Retain the client as a property on a type you define so that // the client's asynchronous network callbacks are executed. let client = Client(spaceId: "<space_id>", environmentId: "<environment_id>", // Defaults to "master" if omitted accessToken: "<access_token>") // Snippets for the images API assume that you already have an `Asset` in memory. var asset: Asset = ... // Type passed into callback will be a UIImage or NSImage depending on the current platform. client.fetchImage(for: asset, with: [ImageOption.formatAs(.png(bits: .standard))]) { (image: Result<UIImage>) in switch result { case .success(let image): // Use the image. case .error(let error): print(error) } }
- fetch and fetchArray consistently taking upwards of 2s
- Privacy manifest updates HOT 4
- 'fetchDecodable'-function does not immediately complete in case of an error
- Can we have a Macro-based annotation approach to serialisation like the Android SDK has? HOT 1
- Why other Contentful swift repositories are archived? HOT 1
- resolveLinksArray doesn't fetch the links HOT 1
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.swift.