Code Monkey home page Code Monkey logo

contentful.swift's Introduction

header

Join Contentful Community Slack   Join Contentful Community Forum

contentful.swift - Swift Content Delivery Library for Contentful

Swift library for the Contentful Content Delivery API and Content Preview API. It helps you to easily access your Content stored in Contentful with your Swift applications.

This repository is actively maintained   MIT License   Build Status   Codebeat badge

Version   Carthage compatible   Swift Package Manager compatible   iOS | macOS | watchOS | tvOS  

What is Contentful?

Contentful provides content infrastructure for digital teams to power websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship their products faster.

Table of contents

Core Features

Getting started

In order to get started with the Contentful Swift library you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful.

Installation

CocoaPods installation
platform :ios, '9.0'
use_frameworks!
pod 'Contentful'

You can specify a specific version of Contentful depending on your needs. To learn more about operators for dependency versioning within a Podfile, see the CocoaPods doc on the Podfile.

pod 'Contentful', '~> 5.0.0'

Carthage installation

You can also use Carthage for integration by adding the following to your Cartfile:

github "contentful/contentful.swift" ~> 5.0.0

Swift Package Manager [swift-tools-version 5.0]

Add the following line to your array of dependencies:

.package(url: "https://github.com/contentful/contentful.swift", .upToNextMajor(from: "5.0.0"))

Your first request

The following code snippet is the most basic one you can use to fetch content from Contentful with this library:

import Contentful

let client = Client(spaceId: "cfexampleapi",
                    environmentId: "master", // Defaults to "master" if omitted.
                    accessToken: "b4c0n73n7fu1")

client.fetch(Entry.self, id: "nyancat") { (result: Result<Entry, Error>) in
    switch result {
    case .success(let entry):
        print(entry)
    case .failure(let error):
        print("Error \(error)!")
    }
}

Accessing the Preview API

To access the Content Preview API, use your preview access token and set your client configuration to use preview as shown below.

let client = Client(spaceId: "cfexampleapi",
                    accessToken: "e5e8d4c5c122cf28fc1af3ff77d28bef78a3952957f15067bbc29f2f0dde0b50",
                    host: Host.preview) // Defaults to Host.delivery if omitted.

Authorization

Grab credentials for your Contentful space by navigating to the "APIs" section of the Contentful Web App. If you don't have access tokens for your app, create a new set for the Delivery and Preview APIs. Next, pass the id of your space and delivery access token into the initializer like so:

Map Contentful entries to Swift classes via EntryDecodable

The EntryDecodable protocol allows you to define a mapping between your content types and your Swift classes that entries will be serialized to. When using methods such as:

let query = QueryOn<Cat>.where(field: .color, .equals("gray"))

client.fetchArray(of: Cat.self, matching: query) { (result: Result<ArrayResponse<Cat>>) in
    guard let cats = result.value?.items else { return }
    print(cats)
}

The asynchronously returned result will be an instance of ArrayResponse in which the generic type parameter is the same type you've passed into the fetch method. If you are using a Query that does not restrict the response to contain entries of one content type, you will use methods that return MixedArrayResponse instead of ArrayResponse. The EntryDecodable protocol extends the Decodable protocol in Swift 4's Foundation standard SDK. The library provides helper methods for resolving relationships between EntryDecodables and also for grabbing values from the fields container in the JSON for each resource.

In the example above, Cat is a type of our own definition conforming to EntryDecodable and FieldKeysQueryable. In order for the library to properly create your model types when receiving JSON, you must pass in these types to your Client instance:

let contentTypeClasses: [EntryDecodable.Type] = [
    Cat.self
    Dog.self,
    Human.self
]

let client = Client(spaceId: spaceId,
                    accessToken: deliveryAPIAccessToken,
                    contentTypeClasses: contentTypeClasses)

The source for the Cat model class is below; note the helper methods the library adds to Swift 4's Decoder type to simplify for parsing JSON returned by Contentful. You also need to pass in these types to your Client instance in order to use the fetch methods which take EntryDecodable type references:

final class Cat: EntryDecodable, FieldKeysQueryable {

    static let contentTypeId: String = "cat"

    // FlatResource members.
    let id: String
    let localeCode: String?
    let updatedAt: Date?
    let createdAt: Date?

    let color: String?
    let name: String?
    let lives: Int?
    let likes: [String]?
  
    // Metadata object if available
    let metadata: Metadata?

    // Relationship fields.
    var bestFriend: Cat?

    public required init(from decoder: Decoder) throws {
        let sys         = try decoder.sys()
        id              = sys.id
        localeCode      = sys.locale
        updatedAt       = sys.updatedAt
        createdAt       = sys.createdAt

        let fields      = try decoder.contentfulFieldsContainer(keyedBy: Cat.FieldKeys.self)
        self.metadata   = try decoder.metadata()
        self.name       = try fields.decodeIfPresent(String.self, forKey: .name)
        self.color      = try fields.decodeIfPresent(String.self, forKey: .color)
        self.likes      = try fields.decodeIfPresent(Array<String>.self, forKey: .likes)
        self.lives      = try fields.decodeIfPresent(Int.self, forKey: .lives)

        try fields.resolveLink(forKey: .bestFriend, decoder: decoder) { [weak self] linkedCat in
            self?.bestFriend = linkedCat as? Cat
        }
    }

    enum FieldKeys: String, CodingKey {
        case bestFriend
        case name, color, likes, lives
    }
}

If you want to simplify the implementation of an EntryDecodable, declare conformance to Resource and add let sys: Sys property to the class and assign via sys = try decoder.sys() during initialization. Then, id, localeCode, updatedAt, and createdAt are all provided via the sys property and don't need to be declared as class members. However, note that this style of implementation may make integration with local database frameworks like Realm and CoreData more cumbersome.

Optionally, decoder has a helper function to decode metadata.

Additionally, the library requires that instances of a type representing an entry or asset must be a class instance, not a struct—this is because the library ensures that the in-memory object graph is complete, but also that it has no duplicates.

Documentation & References

Reference Documentation

The library has 100% documentation coverage of all public variables, types, and functions. You can view the docs on the web or browse them in Xcode. For further information about the Content Delivery API, check out the Content Delivery API Reference Documentation.

Tutorials & other resources

  • This library is a wrapper around our Contentful Delivery REST API. Some more specific details such as search parameters and pagination are better explained on the REST API reference, and you can also get a better understanding of how the requests look under the hood.
  • Check the Contentful for Swift page for Tutorials, Demo Apps, and more information on other ways of using Swift with Contentful

Swift playground

If you'd like to try an interactive demo of the API via a Swift Playground, do the following:

git clone --recursive https://github.com/contentful/contentful.swift.git
cd contentful.swift
make open

Then build the "Contentful_macOS" scheme, open the playground file and go! Note: make sure the "Render Documentation" button is switched on in the Utilities menu on the right of Xcode, and also open up the console to see the outputs of the calls to print.

Example application

See the Swift iOS app on Github and follow the instructions on the README to get a copy of the space so you can see how changing content in Contentful affects the presentation of the app.

Migration

We gathered all information related to migrating from older versions of the library in our Migrations.md document.

Swift Versioning

It is recommended to use Swift 5.0, as older versions of the library will not have fixes backported. If you must use older Swift versions, see the compatible tags below.

Swift version Compatible Contentful tag
Swift 5.0 [ ≥ 5.0.0 ]
Swift 4.2 [ ≥ 4.0.0 ]
Swift 4.1 [2.0.0 - 3.1.2]
Swift 4.0 [0.10.0 - 1.0.1]
Swift 3.x [0.3.0 - 0.9.3]
Swift 2.3 0.2.3
Swift 2.2 0.2.1

Reach out to us

Have questions about how to use this library?

  • Reach out to our community forum: Contentful Community Forum
  • Jump into our community slack channel: Contentful Community Slack

You found a bug or want to propose a feature?

  • File an issue here on GitHub: File an issue. Make sure to remove any credential from your code before sharing it.

You need to share confidential information or have other questions?

  • File a support ticket at our Contentful Customer Support: File support ticket

Get involved

PRs Welcome

We appreciate any help on our repositories. For more details about how to contribute see our Contributing.md document.

License

This repository is published under the MIT license.

Code of Conduct

We want to provide a safe, inclusive, welcoming, and harassment-free space and experience for all participants, regardless of gender identity and expression, sexual orientation, disability, physical appearance, socioeconomic status, body size, ethnicity, nationality, level of experience, age, religion (or lack thereof), or other identity markers.

Read our full Code of Conduct.

contentful.swift's People

Contributors

anton-plebanovich avatar basememara avatar bennichols avatar cf-allstar[bot] avatar chrisballinger avatar cysp avatar dependabot[bot] avatar edwardmp avatar eytanschulman avatar jjolton-contentful avatar khaledgarbaya avatar loudmouth avatar makinwab avatar manmal avatar marcinwyszynski avatar marcolink avatar mariobodemann avatar mariuskatcontentful avatar mariuskurgonas avatar matelo avatar mgratzer avatar neonichu avatar roblinde avatar sajuthomaspattarmatam avatar sebastianludwig avatar t-col avatar tomkowz avatar whitelisab avatar zeusdeux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

contentful.swift's Issues

Should not list Carthage in Framework Search Paths

  • contentful.swift version number: 0.7.2
  • Xcode version number: 8.3.3
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [x] Carthage
    - [ ] Cocoapods

Currently FRAMEWORK_SEARCH_PATHS is set to $(PROJECT_DIR)/Carthage/Build/iOS. This gives a warning when building from source in a consuming workspace:

ld: warning: directory not found for option '-F/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Carthage/Build/iOS'

The correct setup is to not have this and to include ObjectMapper in the Workspace and use Xcode's Implicit Dependency Management. That way it knows how to compile both as a part of Carthage and in the workspace for development: https://www.quora.com/How-should-an-OSS-library-be-structured-for-distribution-with-both-Carthage-and-CocoaPods/answer/Justin-Spahr-Summers

See RxSwiftCommunity/RxKeyboard#25 and RxSwiftCommunity/RxKeyboard#26 where I reported and fixed this for another project.

Carthage support

A friendly request to add Carthage support (build into a framework)

Cannot mapping entries

Hi team,

Do you still support this lib?

I'm using your project but it's crashed here:

let contentTypes = decoder.userInfo[DecoderContext.contentTypesContextKey] as! [ContentTypeId: EntryDecodable.Type]

in ArrayResponse.swift

Beside you Readme is outdated. Please support
Thanks

Allow use in extensions

Can we have APPLICATION_EXTENSION_API_ONLY = YES set, so the SDK can be used in extensions? Currently we are getting a warning that this flag isn't set. When I set it manually it built fine, meaning the SDK isn't using any APIs that would be prohibited.

How to convert long text to HTML String?

Fill in the following details, then delete this line before submitting. (To mark a checkbox change - [ ] to - [x]).

  • contentful.swift version number:
  • Xcode version number:
  • Target operating system(s) and version number(s)
    - [ ] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [ ] Cocoapods

"Anexa 3"

I am getting this response and I want to display in web view, Can you plz let me know hot convert this text to HTML iOS Swift Programing>

Segmentation fault: 11 on x86x64.swiftmodule

Artifact: Contentful.framework.zip
Version: 0.2.1

When attempting to run app that utilizes Contentful.framework on iOS simulator the following error occurs. Note - Issue not present while running on device.

  1. /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccessibility.h:248:12: loading members for 'UIAccessibilityAction'
  2. While type-checking expression at [ - ]
  3. While reading from ${ProjectDir}/Contentful.framework/Modules/Contentful.swiftmodule/x86_64.swiftmodule
  4. While deserializing extension of 'UInt' (ExtensionDecl #166)

Searching on one-to-many references doesn't work

I have a problem with searching on "one-to-many" references fields. I have two Content Types: flyer and shop. In flyer Content Type there is a field named shops which is a "one-to-many" references field (referencing shop content type). I would like to find all flyers which have shop with specific names referenced to them in a shops field. I do it by adding following parameters to the fetchEntries function:

let parameters = ["content_type": "flyer", "fields.shops.sys.contentType.sys.id": "shop", "fields.shops.fields.name[all]": "Warszawa"]

Unfortunately I get this error:

The operation couldn’t be completed. (Contentful.ContentfulError error 1.)

I have made a test and added a field one_shop to flyers content type and searching on one-to-one references seems to be working fine.

Am I doing something wrong or searching on one-to-many references is not supported? I am confused, because this blog post states that it should work, but in the content delivery API docs it is written that :

You can only search on references on fields which link to a single entry. Fields which hold references to many entries or fields with references to assets are not supported.

Which information is correct?

Unable to integrate Contentful Cocoapod into project.

Ok, so.. I totally love the idea of this tool! I can't get it working. There's also disparate documentation between your website & github.

Alright..

First attempt.

Step 1 -> Add Podfile entry

pod 'Contentful'. (FYI, this got me version 0.11.0)

Step 2 -> Reference this documentation: https://www.contentful.com/developers/docs/ios/tutorials/using-delivery-api-with-swift/

Step 3 -> Observe error using code from example ['type Cat does not conform to protocol Resource']

screen shot 2018-01-17 at 9 48 19 am

I dug in and tried adding the 'sys' variable.. because that seemed like it could be the missing expectation from the protocol.. but that didn't work.

Next attempt.

Reviewed the README on the github page. Noticed there it says to use 'EntryDecodable, ResourceQueryable' as protocols on your models. So, I did that!

Still on pod version 0.11.0. But updated to use these.

Getting an error 'undeclared resource 'ResourceQueryable'.

Searching through the Pod headers... there is indeed no reference to this protocol.

Next attempt.

Ok, so I noticed in your example project that your pointing to master.. this obviously makes me extremely nervous, but I decided to try it out. Wa-la! Now ResourceQueryable is indeed included in the pod headers.

However.. now I get an exception on a forced unwrapping.

screen shot 2018-01-17 at 10 20 46 am

So Question

Is this cocoapod in a usable state at it's current head? If so, can you point me to the accurate documentation for using it?

I noticed master is implying a version of 1.0. Indicating that you're thinking you'll reach 1.0 in your next release. Is it in my best interest to just wait for that?

Neonichu Decodable Contains No Sources

When running swift build there is a dependency hang-up; which results in no sources found in Decodable version: 0.3.3. Any insight to resolve this? Much appreciated!

Thanks.

EntryModellable doesn't handle ImplicitOptionals

  • contentful.swift version number: 0.9.3
  • Xcode version number: 9.0
  • Target operating system(s) and version number(s)
    - [x ] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [x ] Carthage
    - [ ] Cocoapods

When I have properties that are required in the CMS, I'd like them to be implicit optionals (end in !) so that I don't have to worry about unwrapping them. Currently anything that is an implicit optional is ignored by then relationshipNames function.

How to retrieve only published entries.

Fill in the following details, then delete this line before submitting. (To mark a checkbox change - [ ] to - [x]).

  • contentful.swift version number: 1.0.1
  • Xcode version number: 9.2
  • Target operating system(s) and version number(s)
    - [ x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [ x] Cocoapods

Apologies if this isn't the place. I'm not sure if it's a bug or not.. Should I be receiving entries that aren't published when I query for them? If so, how do I say that I only want ones that have been published? Or I'd be happy to just receive a state of 'published' or 'unpublished'.

Just to clarify.. I AM receiving entries that I've 'unpublished' through the contentful CMS interface. And I have no way of determining their published status.

Pretty basic code:

screen shot 2018-03-16 at 12 56 23 pm

Swift 3.0 support in general

Hi,

I see the Carthage and Cocoapods installation for Swift 3 is not yet supported for Contentful.

Is there another way to install this Swift 3 branch that is supported / working?

Improve error message for lacking content type information

Currently, if an SDK consumer doesn't pass in an array of EntryDecodable types to the client on initialization, but then attempts to use fetch methods that will map to EntryDecodable, the SDK will crash. While this crash is intentional, the implicitly unwrapped optional that causes it doesn't provide much info to SDK users.

This crash should be swapped out for either a fatalError with a descriptive error or an assertionFailure.

Swift example project

  • contentful.swift version number: 0.9.2
  • Xcode version number: 9.0 beta 6
  • Target operating system(s) and version number(s)
    - [x] iOS: 10
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [x] Cocoapods

Hello guys,

I am having problems setting up even the simplest of things in my project using your SDK. I tried looking into the tests, documentation, tutorials but they are way too generic.

What I need is extremely simple, yet I am struggling to achieve it. I basically just want to fetch posts from the Contentful. Lets say I have model named "Post" which reflects the post, posts can be put into categories reflected by another model called "Category".

What I tried to fetch the posts is this:

let query = Query(where: "content_type", .equals("post"))

client.fetchEntries(with: query) { result in
           switch result {
           case .success(let entriesArrayResponse):
                print(entriesArrayResponse.items)
           case .error(let error):
               print("error.localizedDescription")
           }
       }

yet all I get back is error saying - Contentful.ContentfulError error 1.

I tried going through queries for contentTypes, tried fetching all entries, but I am not able to find the right content_type to fetch just the posts, nothing else.

I am really struggling, it feels like using just a raw JSON response would have been quicker and easier, I cannot get anything to work with this SDK :/ Are you guys planning on creating some sample projects which would use all the SDK features and provide some test user access to the Contentful space they would be using? So we get to see a real use of the Contentful iOS SDK.

Parse throws DecodingError.missingKey for key "Message"

We created some models in Contentful but the SDK always breaks / throws at

func parse(_ json: Any, _ keyPath: KeyPath) throws -> Any {
    var currentDict = json
    
    for (index, key) in keyPath.keys.enumerated() {
        guard let result = try NSDictionary.decode(currentDict)[key] else {
            let currentPath = keyPath.keys[0 ..< index]
            let metadata = DecodingError.Metadata(path: Array(currentPath), object: currentDict, rootObject: json)
            throw DecodingError.missingKey(key, metadata)
        }
        
        currentDict = result
    }
    
    return currentDict
}

throw DecodingError.missingKey(key, metadata) key: message

We are using

Contentful (0.3.1):
    - Decodable (~> 0.5)
    - Interstellar (~> 2.0.0)

SwiftLint warnings

  • contentful.swift version number: 0.8.0
  • Xcode version number: 8.3.3
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [x] Carthage
    - [ ] Cocoapods

Currently there are 95 SwiftLint warnings when building the project:

Loading configuration from '.swiftlint.yml'
Invalid configuration for 'line_length'. Falling back to default.
configuration error: 'identifier_name' is not a valid rule identifier
Valid rule identifiers:
empty_count
redundant_optional_initialization
trailing_semicolon
statement_position
type_name
unused_enumerated
todo
legacy_constant
force_cast
nimble_operator
unused_closure_parameter
number_separator
comma
sorted_imports
implicit_getter
legacy_cggeometry_functions
force_unwrapping
leading_whitespace
cyclomatic_complexity
function_body_length
control_statement
empty_parentheses_with_trailing_closure
dynamic_inline
type_body_length
unused_optional_binding
operator_whitespace
closure_spacing
prohibited_super_call
vertical_whitespace
object_literal
valid_docs
redundant_void_return
large_tuple
trailing_whitespace
mark
empty_parameters
legacy_nsgeometry_functions
shorthand_operator
closing_brace
class_delegate_protocol
colon
closure_parameter_position
nesting
switch_case_on_newline
file_header
conditional_returns_on_newline
trailing_newline
missing_docs
variable_name
redundant_nil_coalescing
private_unit_test
compiler_protocol_init
return_arrow_whitespace
operator_usage_whitespace
attributes
overridden_super_call
vertical_parameter_alignment
first_where
private_outlet
generic_type_name
explicit_init
legacy_constructor
closure_end_indentation
custom_rules
function_parameter_count
syntactic_sugar
trailing_comma
void_return
valid_ibinspectable
opening_brace
line_length
weak_delegate
force_try
redundant_string_enum_value
file_length
Linting Swift files in current working directory
Linting 'Package.swift' (1/23)
Linting 'Client+AppKit.swift' (2/23)
Linting 'ArrayResponse.swift' (3/23)
Linting 'Asset.swift' (4/23)
Linting 'Client.swift' (5/23)
Linting 'ClientConfiguration.swift' (6/23)
Linting 'ContentModellable.swift' (7/23)
Linting 'ContentType.swift' (8/23)
Linting 'Date.swift' (9/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ArrayResponse.swift:29: warning: Line Length Violation: Line should be 120 characters or less: currently 133 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ArrayResponse.swift:75: warning: Line Length Violation: Line should be 120 characters or less: currently 133 characters (line_length)
Linting 'Entry.swift' (10/23)
Linting 'Error.swift' (11/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Asset.swift:29: warning: Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Asset.swift:46: warning: Line Length Violation: Line should be 120 characters or less: currently 122 characters (line_length)
Linting 'Field.swift' (12/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ClientConfiguration.swift:46: warning: Line Length Violation: Line should be 120 characters or less: currently 145 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ClientConfiguration.swift:106: warning: Line Length Violation: Line should be 120 characters or less: currently 138 characters (line_length)
Linting 'ImageOptions.swift' (13/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:459:47: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:470:47: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:528:53: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:540:53: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:605:47: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:628:47: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:72: warning: Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:204: warning: Line Length Violation: Line should be 120 characters or less: currently 124 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:206: warning: Line Length Violation: Line should be 120 characters or less: currently 127 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:208: warning: Line Length Violation: Line should be 120 characters or less: currently 124 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:213: warning: Line Length Violation: Line should be 120 characters or less: currently 132 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:223: warning: Line Length Violation: Line should be 120 characters or less: currently 128 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:226: warning: Line Length Violation: Line should be 120 characters or less: currently 124 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:233: warning: Line Length Violation: Line should be 120 characters or less: currently 132 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:241: warning: Line Length Violation: Line should be 120 characters or less: currently 128 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:245: warning: Line Length Violation: Line should be 120 characters or less: currently 124 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:257: warning: Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:328: warning: Line Length Violation: Line should be 120 characters or less: currently 137 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:356: warning: Line Length Violation: Line should be 120 characters or less: currently 136 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:390: warning: Line Length Violation: Line should be 120 characters or less: currently 144 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:391: warning: Line Length Violation: Line should be 120 characters or less: currently 129 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:399: warning: Line Length Violation: Line should be 120 characters or less: currently 136 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:422: warning: Line Length Violation: Line should be 120 characters or less: currently 147 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:428: warning: Line Length Violation: Line should be 120 characters or less: currently 144 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:444: warning: Line Length Violation: Line should be 120 characters or less: currently 125 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:459: warning: Line Length Violation: Line should be 120 characters or less: currently 127 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:484: warning: Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:495: warning: Line Length Violation: Line should be 120 characters or less: currently 123 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:529: warning: Line Length Violation: Line should be 120 characters or less: currently 127 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:554: warning: Line Length Violation: Line should be 120 characters or less: currently 143 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:565: warning: Line Length Violation: Line should be 120 characters or less: currently 135 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:566: warning: Line Length Violation: Line should be 120 characters or less: currently 125 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:581: warning: Line Length Violation: Line should be 120 characters or less: currently 132 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Client.swift:592: warning: Line Length Violation: Line should be 120 characters or less: currently 125 characters (line_length)
Linting 'Link.swift' (14/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ContentModellable.swift:14:5: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ContentModellable.swift:61: warning: Line Length Violation: Line should be 120 characters or less: currently 139 characters (line_length)
Linting 'Locale.swift' (15/23)
Linting 'Persistence.swift' (16/23)
Linting 'Query.swift' (17/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Entry.swift:54: warning: Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)
Linting 'Resource.swift' (18/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Error.swift:110:25: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Error.swift:65: warning: Line Length Violation: Line should be 120 characters or less: currently 121 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Error.swift:70: warning: Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Error.swift:146: warning: Line Length Violation: Line should be 120 characters or less: currently 142 characters (line_length)
Linting 'SignalUtils.swift' (19/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Field.swift:48:12: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
Linting 'Space.swift' (20/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ImageOptions.swift:80: warning: Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ImageOptions.swift:83: warning: Line Length Violation: Line should be 120 characters or less: currently 124 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ImageOptions.swift:104: warning: Line Length Violation: Line should be 120 characters or less: currently 129 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/ImageOptions.swift:229: warning: Line Length Violation: Line should be 120 characters or less: currently 175 characters (line_length)
Linting 'SyncSpace.swift' (21/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Link.swift:15:12: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Link.swift:40:12: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Link.swift:25: warning: Line Length Violation: Line should be 120 characters or less: currently 123 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Link.swift:71: warning: Line Length Violation: Line should be 120 characters or less: currently 132 characters (line_length)
Linting 'Sys.swift' (22/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Locale.swift:114: warning: Line Length Violation: Line should be 120 characters or less: currently 160 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Locale.swift:117: warning: Line Length Violation: Line should be 120 characters or less: currently 137 characters (line_length)
Linting 'Client+UIKit.swift' (23/23)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Resource.swift:20:12: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Resource.swift:57: warning: Line Length Violation: Line should be 120 characters or less: currently 150 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Resource.swift:102: warning: Line Length Violation: Line should be 120 characters or less: currently 127 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:15: warning: Line Length Violation: Line should be 120 characters or less: currently 121 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:51: warning: Line Length Violation: Line should be 120 characters or less: currently 122 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:78: warning: Line Length Violation: Line should be 120 characters or less: currently 146 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:103: warning: Line Length Violation: Line should be 120 characters or less: currently 124 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:206: warning: Line Length Violation: Line should be 120 characters or less: currently 134 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:248: warning: Line Length Violation: Line should be 120 characters or less: currently 128 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:257: warning: Line Length Violation: Line should be 120 characters or less: currently 143 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:268: warning: Line Length Violation: Line should be 120 characters or less: currently 132 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:272: warning: Line Length Violation: Line should be 120 characters or less: currently 128 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:295: warning: Line Length Violation: Line should be 120 characters or less: currently 122 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:296: warning: Line Length Violation: Line should be 120 characters or less: currently 147 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:307: warning: Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:353: warning: Line Length Violation: Line should be 120 characters or less: currently 142 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:356: warning: Line Length Violation: Line should be 120 characters or less: currently 143 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:368: warning: Line Length Violation: Line should be 120 characters or less: currently 132 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:372: warning: Line Length Violation: Line should be 120 characters or less: currently 128 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:377: warning: Line Length Violation: Line should be 120 characters or less: currently 127 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:402: warning: Line Length Violation: Line should be 120 characters or less: currently 122 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:403: warning: Line Length Violation: Line should be 120 characters or less: currently 147 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:413: warning: Line Length Violation: Line should be 120 characters or less: currently 141 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:463: warning: Line Length Violation: Line should be 120 characters or less: currently 133 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:476: warning: Line Length Violation: Line should be 120 characters or less: currently 121 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:478: warning: Line Length Violation: Line should be 120 characters or less: currently 133 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:514: warning: Line Length Violation: Line should be 120 characters or less: currently 138 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:581: warning: Line Length Violation: Line should be 120 characters or less: currently 133 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:582: warning: Line Length Violation: Line should be 120 characters or less: currently 141 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:587: warning: Line Length Violation: Line should be 120 characters or less: currently 138 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:634: warning: Line Length Violation: Line should be 120 characters or less: currently 138 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:685: warning: Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:686: warning: Line Length Violation: Line should be 120 characters or less: currently 145 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:698: warning: Line Length Violation: Line should be 120 characters or less: currently 137 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Query.swift:704: warning: Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/SignalUtils.swift:19: warning: Line Length Violation: Line should be 120 characters or less: currently 147 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/SignalUtils.swift:30: warning: Line Length Violation: Line should be 120 characters or less: currently 139 characters (line_length)
/Users/bejones/Development/project/Carthage/Checkouts/contentful.swift/Sources/Sys.swift:15:12: warning: Variable Name Violation: Variable name should be between 3 and 40 characters long: 'id' (variable_name)
Done linting! Found 96 violations, 0 serious in 23 files.

The framework contains disallowed file

Hi,

I got the following error when submitting the app to iTunes:

ERROR ITMS-90206: "Invalid Bundle. The bundle at '***.app/Frameworks/Contentful.framework' contains disallowed file 'Frameworks'."

It seems that Contentful.framework contains unnecessary frameworks.

Carthage 0.16.2, Xcode 7.3

Crash on simple QUERY

HI,
I'm trying to use your SDK - 1.0.1 - and along with the issues pointed out previously that I'm encountering, I'd like to use fetchMappedEntries with either MixedMappedArrayResponse or MappedArrayResponse to get all entries I have and sort them into the EntryDecodable models I'm creating.

So i'd like to fetch everything and then map to entries. I'm trying something simple like this but it crashes:

let client = Client(spaceId: spaceId, accessToken: accessToken) 
let query = Query() 
client.fetchMappedEntries(matching: query) { result in 
print("COMPLETION") 
}

Am I attempting to use 'MixedMappedArrayResponse' or MappedArrayResponse correctly?

What kind of query do I create to get everything and then use your automatic mapping methods to the EntryDecodable models?

tvOS support

Hi, I am working on tvOS app,earlier I used ContentfulDeliverAPI pod for iOS, Now I tried to use this repo for tvos but it throws error when I import it. Or should I be using this repo for tvos [https://github.com/contentful/tvful]. Please advice.

Modellable Child <-> Parent Relationship Creates Endless Loop

  • contentful.swift version number: 0.8.0
  • Xcode version number: 9.0 +
  • Target operating system(s) and version number(s)
    - [X] iOS:
    - [X] tvOS:
    - [X] watchOS:
    - [X] macOS:
  • Package manager:
    - [X] Carthage
    - [X] Cocoapods

It appears when I have a parent that contains an array of children, and the children reference the parent, during the mapping process there is an infinite loop that causes the framework to crash. The child will try to map the parent, then the parent re-attempts at mapping the child which then causes the child try to map the parent again, and so on..... until the crash.

In my code I am currently mapping my data manually until this is fixed, but hopefully it inspires a solution on your side to fix it. For this example imagine a Series, which contains Seasons, which contains Videos. I may need each entity at some point to reference it's parent. Thus the Video would need to tell me which season it is part of, and each season may need to tell me which series it is part of.

final class Series {
    static let contentTypeId: String = "series"
    var seasons : [Season]?

    init?(entry: Entry) {
        ...
        if let seasonLinks = entry.fields["seasons"] as? [Link] {
            var seasonArray = [Season]()
            
            for link in seasonLinks {
                switch link {
                case .entry(let seasonEntry):
                    if let season = Season(entry: seasonEntry, parentSeries : self) {
                        seasonArray.append(season)
                    }
                default:
                    continue
                }
            }
            
            seasons = seasonArray
        }   
    }
}

final class Season {
    static let contentTypeId: String = "season"
    var parentSeason : Series?
   
    init?(entry: Entry, parentSeries : Series? = nil) {
       ...
        if parentSeries != nil {
            self.parentSeries = parentSeries
        } else {
            // parse the parent
        }
    }
}

final class Video  {
    static let contentTypeId: String = "video"
    var parentSeason : Season?
   
    init?(entry: Entry, parentSeason : Season? = nil) {
        ...
        if parentSeries != nil {
            self.parentSeries = parentSeries
        } else {
            // parse the parent
        }
    }
}

If there is a way to identify the parent relationship, and you can tell the child "Hey, I'm your elder don't map me", the child can mapping it and stop the infinite loop. hopefully this inspires some creativity on your part to identify these relationships during mapping :)

Instructions on spaceId & API access token configuration...

Fill in the following details, then delete this line before submitting. (To mark a checkbox change - [ ] to - [x]).

  • contentful.swift version number:
  • Xcode version number:
  • Target operating system(s) and version number(s)
    - [ ] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [ ] Cocoapods

Just spent 15 minutes digging around on how to set these up with the cocoapod. I'm sure I could figure it out eventually.. but could you guys just add this to the README? Thanks!

Expose ContentModel init

  • contentful.swift version number: 0.9.1
  • Xcode version number: 8.3.3
  • Target operating system(s) and version number(s)
    - [x] iOS: Any Supported Version
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [x] Cocoapods

While trying to use client.fetchMappedEntries I realised it's based on ContentModelobject defined in Client.

However, ContentModel initialiser is inaccessible due to internal protection level. I can't create a new ContentModel for my client, and so, can't map entries. To workaround, I exposed ContentModel init as public but it might be something useful to implement for others except if I missed something else?

Thanks

Contentful.Entry.fields does not contain empty fields

  • contentful.swift version number: 0.6.0
  • Xcode version number: 8.3.2
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [x] Carthage
    - [ ] Cocoapods

Hi,

After updating of field to empty value we do not get fields with empty value.
It's very important after update of entry in coredata. We do not want to recreate fully entry - just update fields we receive.

I believe it should return nil value even for not presented values.

Thanks in advance.

Fetching for the first time but getting an error 3?

  • contentful.swift version number: 0.10.2
  • Xcode version number: 9.2
  • Target operating system(s) and version number(s)
    - [x] iOS: 11.0
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [x] Cocoapods

I just tried using it for the first time, and I went over the setup guide and I'm getting this error:

The operation couldn’t be completed. (Contentful.SDKError error 3.)

What does it mean? I have initialized the client with its associated values.

Please Update Your Documentation (3 Months of Inconsistencies)

  • contentful.swift version number: 0.8.0
  • Xcode version number: 8.3+
  • Target operating system(s) and version number(s)
    - [x] iOS: Any Supported Version
    - [x] tvOS: Any Supported Version
    - [x] watchOS: Any Supported Version
    - [x] macOS: Any Supported Version
  • Package manager:
    - [x] Carthage
    - [x] Cocoapods

Please update your Documentation for Swift! This is killing me, not only are we being forced to adapt mapping frameworks that aren't part of the current workflow, there are no clear examples documented as part of your framework on how to adapt your Modellable protocol. Since the library does not just return a JSON response, nor provide access to included entries, this is taking way longer than it should from a development perspective.

Deleted objects are not received sometimes.

  • contentful.swift version number: 0.6.0
  • Xcode version number: 8.3
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [x] Carthage
    - [ ] Cocoapods

I do not get callbacks about deleted objects sometimes and can not make local storage consistent.
I use this code for syncing:
if let syncToken = syncToken {
let syncSpace = SyncSpace(client: client, syncToken: syncToken, delegate: self)
syncSpace.sync(completion: syncCompletion)
} else {
client.initialSync { (result: Result<Contentful.SyncSpace>) in
switch result { ... }
syncCompletion(result)
}
}

My space id is "it3h0h0p6zju"
My sync token is "w5ZGw6JFwqZmVcKsE8Kow4grw45QdyYjw5Z6LSxvPsKBeCZqwq5lwrZNKxbDm8OEWhxVCsK9w5whJcOKIsOcwqHDqwJxaMKxb1XDhydRwqQgwrBKKA9PDDRxeV88UF0DPMKHDMKXw4xnBA"

Can you let me know some information from token? For example date of changes? And a list of changes I should receive for it?
I do not get callbacks about some deleted entries, but it works for most of them.

Thanks in advance.

Sync crashes if the contentful output does not contain default locale data

Our output only contains de_DE data. That leads to the assertion assert(mapping.count > 0, "Empty mapping for \(type)") in ContentfulSynchronizer.swift:165 in create(_:fields:type:mapping) to fail.

In the create methods the ContentfulSynchronizer calls deriveMapping with foo.fields.keys. foo.fields takes the fields set from the localizedFields map that's mapped to the "current locale", or the defaultLocale as fallback (see Contentful/Assets.swift or Entry.swift).

The "current locale" is saved on the json NSDictionary (Client.swift:164). But not as additional entry or anything, but using objc_setAssociatedObject (in Decoding.swift). When tried to be retrieved in determineDefaultLocale it's not there anymore.

The bug comes down to Client.swift:166:

(lldb) po (json as! NSDictionary).client
▿ Optional<Client>
  ▿ some : <Client: 0x6000000b9020>
(lldb) po ((json as! [String: Any]) as! NSDictionary).client
nil

p.s. personal opinion: objc_setAssociatedObject is almost never a good idea and should be avoided.

Use optional initializers instead of throw

During development I use a "Swift Error" breakpoint. Contentful throws unnecessary exceptions while working totally fine. This is confusing and bad style. For example ContentfulError throws instead of returning nil. Optional initializers should be used instead.

Link's not parsing correctly

  • contentful.swift version number: 0.6.0
  • Xcode version number: 8.3.2
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [x] Carthage
    - [ ] Cocoapods

Sometimes in fields for entry it contains row dictionary instead of link object for value:

Links for my object relationsships become:
"categories": <__NSArrayI 0x600000625960>(
{
sys = {
id =12345;
linkType = Entry;
type = Link;
};
}

but in some cases it is valid link
"categories": [Contentful.Link.unresolved(Contentful.LinkSys(id: "12345", linkType: "Entry"))]

*12345 - is stub value

I'm not sure in which cases it appears but seems like a critical bug.

Disable code coverage in test scheme

  • contentful.swift version number: 0.8
  • Xcode version number: 9.0
  • Target operating system(s) and version number(s)
    - [ x ] iOS: 11.0
  • Package manager:
    - [ x ] Carthage

Please disable 'Gather coverage data' by default in the Test scheme - when using Carthage it can cause a submission error (Invalid Bundle - Disallowed LLVM instrumentation) when submitting a build with Xcode 9 that contains the contentful framework.

Technical details here:
https://forums.developer.apple.com/thread/81893

EntryModellable doesn't properly synthesize lists.

  • contentful.swift version number: 0.9.3
  • Xcode version number: 9.0
  • Target operating system(s) and version number(s)
    - [x ] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [x ] Carthage
    - [ ] Cocoapods

When I have a list of objects or assets, they don't synthesize to the associated objects in my models. I believe this is due to the way the relationshipNames function is determining what is a valid relationship and not taking arrays into account. I tried to fix it there, but it didn't seem to work. Maybe there is more going on in the cache in order to get the models into the arrays?

Carthage fails to build in Swift 3

I've tried to use carthage update --platform iOS with Swift 3 branch, but it fails to build by referencing CocoaPods.

*** Building scheme "Contentful" in Contentful.xcworkspace
** BUILD FAILED **


The following build commands failed:
    PhaseScriptExecution Check\ Pods\ Manifest.lock /Users/****/Library/Developer/Xcode/DerivedData/Contentful-auzeobpdvgvojlduvsjargjwtodp/Build/Intermediates/Contentful.build/Release-iphoneos/Contentful.build/Script-40E859107A3926159C69D196.sh
(1 failure)
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
A shell task (/usr/bin/xcrun xcodebuild -workspace /Users/****/Desktop/****/Carthage/Checkouts/contentful.swift/Contentful.xcworkspace -scheme Contentful -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
** BUILD FAILED **

In my Cartfile I have this:

github "contentful/contentful.swift" "swift-3.0"

Mapping result to struct

Any chance of a simple example of mapping result to a struct (or point to documentation example)? Thanks


import Decodable

struct Cat {
    let name: String
}


extension Cat:Decodable {
    static func decode(j: AnyObject) throws -> Cat {
        return try Cat(
            name: j => "nested" => "name",
        )
    }
}

let client = Client(spaceIdentifier: "cfexampleapi", accessToken: "b4c0n73n7fu1")
client.fetchEntry("nyancat") { (result) in
    switch result {
        case let .Success(entry):
            print(entry)

           // Now what? Map entry to Cat, using decode perhaps?

        case .Error(_):
            print("Error!")
    }
}

Readme improvements

Since cocoadocs is sunsetted some users are having trouble finding the reference documentation, which is still available via github pages.
There are also some other simple improvements that could be made.

TODO's

  • Add link to reference docs
  • Add information about the necessary import Interstellar statements.
  • Add links to new example app

How to fetch entries with all locales and access localized data

  • contentful.swift version number: 0.10.2
  • Xcode version number: 9.0
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [x] Cocoapods

I'm having issues accessing localised entries. That's how i tried to do it now:

  1. I fetch the entry with 'fetchEntries' function and add "locale": "*" to query. It does work, i can see that that private var 'includes' has localizableFields with both locales.
  2. On response object i iterate on 'items' and call setLocale() function
  3. When trying to access fields on Entries from items array, that i called setLocale function, the content is still has default locale.

Do I do something wrong or there is a bug?

Thanks!

How to use entries() with linked entry IDs?

  • contentful.swift version number: 5.0
  • Xcode version number: 8.3.2
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [x] Cocoapods

How do I use client.fetchEntries() with linked entries? I see in Link.swift the Link enum has a variable for it's resolved entry, but it is not publicly accessible. Also includedEntries in ArrayResponse is marked internal. So how do I access the linked entries?

Query result - fields that're arrays of Assets aren't mapped into objects

  • contentful.swift version number: 1.0.0-beta1
  • Xcode version number: 9.0.1 (9A1004)
  • Target operating system(s) and version number(s)
    - [ ] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [x] macOS: 10.12
  • Package manager:
    - [ ] Carthage
    - [x] Cocoapods

Hello,

It seems that if you have model that has a field which is an array of Assets then those assets are not map into objects.

Please check the code below. I have entity SomeModel with topImages field which is always mapped to nil. The other field named topVideo which points to a single Asset is mapped correctly.

final class SomeModel: EntryDecodable, ResourceQueryable {
    static let contentTypeId: ContentTypeId = "pregnancyAndBaby"
    
    let sys: Sys

    var topVideo: Asset?
    var topImages: [Asset]?
    
    public required init(from decoder: Decoder) throws {
        sys = try decoder.sys()
        let fields = try decoder.contentfulFieldsContainer(keyedBy: SomeModel.Fields.self)

        try fields.resolveLink(forKey: .topVideo, decoder: decoder) { [weak self] topVideo in
            self?.topVideo = topVideo as? Asset // mapped correctly
        }
        try fields.resolveLinksArray(forKey: .topImages, decoder: decoder) { [weak self] topImages in
            self?.topImages = topImages as? [Asset] // not mapped at all, it's nil (!)
        }
    }
    
    enum Fields: String, CodingKey {
        case topImages, topVideo
    }
}

I fetch entities using the following code:

func fetchSomeEntries(completion: @escaping((Bool, [SomeModel]) -> ())) {
    let query = QueryOn<SomeModel>()
    client.fetchMappedEntries(matching: query) { (result: Result<MappedArrayResponse<SomeModel>>) in
        switch result {
        case .success(let itemsResonse):
            completion(true, itemsResonse.items)
        case .error(let error):
            print("Error fetching entries: \(error)")
            completion(false, [SomeModel]())
        }
    }
}

The problem is that resolveLinksArray callback returns topImages as Any and it fails:
self?.topImages = topImages as? [Asset]

What is more when I have a field which is an array of my custom entries (for instance [SomeOtherEntries]) it gets mapped correctly. So it seems that mapping does not work for [Asset].

Is that a bug in SDK? Or maybe topImages should be resolved in a different way in SomeModel constructor?

Feature Request: Denormalize JSON response

In order to enable integration with apps with mature data models, the SDK should offer methods to return raw JSON. This JSON should not necessarily be a simple forwarding of the API response; rather, it should perform a join operation on Link fields so that Links are deserialized from simple id references to complete JSON object representations.

See #107 for more information.

Issue with entry.fields

Hello! I'm using the iOS SDK for Swift 2.3.

I have an entry which has an array of Stores (another type of entries) linked inside a field with "stores" key. When I try to fetch that entry, I encountered a problem trying to get useful info inside the fields structure:

	func fetchArray(withIdentifier identifier: String,
	                key: String,
	                success: @escaping (String, [Entry]) -> (),
	                failure: @escaping (NSError) -> ()) {
		client.fetchEntry(identifier: identifier) { result in
			switch result {
			case let .success(entry):
                guard let entries = entry.fields[key] as? [Entry] else { return failure(ContentfulError.keyMismatch(key) as NSError) } // Problem here because cast always fails
				success(entry.fields["description"] as? String ?? "", entries)
				
			case let .error(error):
				failure(error as NSError)
			}
		}
	}

The problem is in the guard clausule: entry.fields[key] as? [Entry] always fails because fields[key] is always of type Any. I've tried to convert it to other objects without success. And I cannot parse it. This is also happening in the Swift 3 SDK. However, if I do exactly the same but with the Objective-C SDK, the cast to [CDAEntry] doesn't fail:

    func fetchArray(withIdentifier identifier: String,
                    key: String,
                    success: @escaping (String, [CDAEntry]) -> (),
                    failure: @escaping (NSError) -> ()) {
        client.fetchEntry(withIdentifier: identifier,
                          success: { (response: CDAResponse, entry: CDAEntry) in
                            guard let entries = entry.fields[key] as? [CDAEntry] else { return failure(ContentfulError()) }
                            success(entry.fields["description"] as! String, entries)
        }) { (response: CDAResponse?, error: Error) in
            failure(error as NSError)
        }
    }

Another interesting thing is that, using the Objective-C SDK, the linked entries (stores) are complete with all the Store model info. But in the Swift SDK, the Any object received only contains partial info (ids and so. I was able to know this because I printed .fields[key] in the debugger).

What is happening here? Is there really an issue or am I missing something?
Thanks in advance!

Pod not up to date

Hello Contentful,

Your pod is not up to date, please create a new release that I can tag in my pod file !

Also, the pod is nowhere to find if I don't add :github '', :tag '0.1.0'

Use of undeclared type 'ResourceQueryable'

  • contentful.swift version number: 0.11.0
  • Xcode version number: 9.2
  • Target operating system(s) and version number(s)
  • iOS: 11.2
  • Package manager:
  • Cocoapods: 1.3.1

When attempting the example written in the READMe file on this repository, I get this error: Use of undeclared type 'ResourceQueryable'.

I did some quick digging to see that the ResourceQueryable protocol is implemented in a Swift file called TypedQuery.swift. When looking at my Contentful installation in my Xcode project, I do not see this file, and therefore Xcode does not see this protocol implementation.

I tried removing Contentful as a pod and readding, but to no avail the problem persists.

How can I get the TypedQuery.swift file into my project via Cocoapods?

'contentTypeInfo' is inaccessible due to 'private' protection level in 'Sys.swift'

  • contentful.swift version number: 0.10.1
  • Xcode version number: 9.0
  • Target operating system(s) and version number(s)
    - [x] iOS:
    - [ ] tvOS:
    - [ ] watchOS:
    - [ ] macOS:
  • Package manager:
    - [ ] Carthage
    - [x] Cocoapods

When trying to compile the pod i get the error that 'contentTypeInfo' has a private protection level and cannot be accessed in the initialiser.

File: Sys.swift
Line number: 52

Error Callback not called when no network

  • contentful.swift version number: 0.7.5
  • Xcode version number: 8.3.3
  • Target operating system(s) and version number(s)
    • iOS: all
    • tvOS: all
    • watchOS: all
    • macOS: all

When there is no network connection, error callbacks are not called.

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.