Code Monkey home page Code Monkey logo

Comments (10)

loudmouth avatar loudmouth commented on September 18, 2024

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.

tapwork avatar tapwork commented on September 18, 2024

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)

screen shot 2017-05-31 at 09 00 19

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.

loudmouth avatar loudmouth commented on September 18, 2024

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 your ContentfulSynchronizer instance.

Thanks.

from contentful.swift.

tapwork avatar tapwork commented on September 18, 2024

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.

loudmouth avatar loudmouth commented on September 18, 2024

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.

loudmouth avatar loudmouth commented on September 18, 2024

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.

tapwork avatar tapwork commented on September 18, 2024

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.

loudmouth avatar loudmouth commented on September 18, 2024

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.

tapwork avatar tapwork commented on September 18, 2024

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.

loudmouth avatar loudmouth commented on September 18, 2024

Fixed in #70

from contentful.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.