/contentful.swift

A delightful Swift interface to Contentful's content delivery API.

Primary LanguageSwiftMIT LicenseMIT

contentful.swift

Version Carthage compatible Platform License Build Status Coverage Status codebeat badge

Swift SDK for Contentful's Content Delivery API.

Contentful is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.

The Contentful Swift SDK hasn't reached 1.0.0 and is therefore subject to API changes. However, it provides a more usable API than the Objective-C SDK and has support for more API features.

Full feature comparison of contentful.swift & contentful.objc

CDA Features contentful.swift contentful.objc
API coverage*
Images API
Search Parameters 🚫
Fallback locales for sync api 🚧 🚫
Rate limit handling 🚫 🚫

*API Coverage definition: all endpoints can be interfaced with and complex queries can be constructed by passing in dictionaries of http parameter/argument pairs. Note that the Swift SDK provides much more comprehensive coverage and takes advantage of type system, outdoing the "stringly typed" interface that the Objective-C SDK offers.

Usage

let client = Client(spaceId: "cfexampleapi", accessToken: "b4c0n73n7fu1")
client.fetchEntry("nyancat") { (result: Result<Entry>) in
    switch result {
        case let .success(entry):
            print(entry)
        case .error(let error):
            print("Error \(error)!")
    }
}

Documentation

For further information, check out the Content Delivery API Reference Documentation.

Swift Versioning

The Contentful Swift SDK requires, at minimum, Swift 2.2 and therefore Xcode 7.3.

Swift version Compatible Contentful tag
Swift 3.0 v0.5.0
Swift 2.3 v0.2.3
Swift 2.2 v0.2.1

While there have been some patches applied to the Swift-2.3 branch, no future maintainence is intended on this branch. It is recommended to upgrade to Swift 3 and use the newest version of contentful.swift.

CocoaPods installation

CocoaPods is a dependency manager for Swift, which automates and simplifies the process of using 3rd-party libraries like the Contentful Delivery API in your projects.

platform :ios, '8.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', '~> 0.5.0' 

Note that for Swift 2.3 support (contentful.swift v0.2.3) you will need to add a post-install script to your Podfile if installing with Cocoapods:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '2.3'
    end
  end
end

Carthage installation

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

github "contentful/contentful.swift" ~> 0.5.0

License

Copyright (c) 2016 Contentful GmbH. See LICENSE for further details.