Skip to content

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

License

Notifications You must be signed in to change notification settings

DaydreamNation/contentful.swift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contentful

contentful.swift

Version Carthage compatible Swift Package Manager 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. It is recommended to use contentful.swift over contentful.objc as future development at Contentful will focus on Swift rather than Objective-C. However, if your project must utilize Contentful's Content Managamement API, Objective-C is the only  language supported at the moment. See ContentfulManagementAPI at Cocoapods.org for more information.

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 .success(entry):
            print(entry)
        case .error(let error):
            print("Error \(error)!")
    }
}

EntryModellable and MappedContent

The EntryModellable protocols allows you to define types that will be mapped from Entrys of the various content types in your Contentful space. When using methods such as:

func fetchMappedEntries(with query: Query) -> Observable<Result<MappedContent>>

the asynchronously returned result will be an instance of MappedContent which will contain a dictionary which maps content type identifiers to arrays of EntryModellable (types of your own definition) that have been fetched. Note that these features are in beta and the API is subject to change.

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.

Reference Documentation

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

Xcode versioning

Unless you're using Swift 2.x, the project is built and unit tested in Travis CI on both Xcode 8.3 and Xcode 9. You should be able to integrate the SDK with either version of Xcode.

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 [0.3.0 - 0.9.3]
Swift 2.3 0.2.3
Swift 2.2 0.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.9.3' 

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.9.3

License

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

About

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

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.2%
  • Ruby 1.6%
  • Shell 1.5%
  • Other 0.7%