contentful.swift
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, yet, but provides a much nicer API than using the Objective-C SDK from Swift. If you need some of the more advanced features, like offline persistence using Core Data, you have to stick to the Objective-C SDK for now. Check out our Swift example in this case.
Usage
let client = Client(spaceIdentifier: "cfexampleapi", accessToken: "b4c0n73n7fu1")
client.fetchEntry("nyancat") { (result) in
switch result {
case let .Success(entry):
print(entry)
case .Error(_):
print("Error!")
}
}
Documentation
For further information, check out the Developer 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.3.1 |
| Swift 2.3 | v0.2.3 |
| Swift 2.2 | v0.2.1 |
Carthage installation
You can also use Carthage for integration by adding this to your Cartfile:
github "contentful/contentful.swift" ~> 0.3.1
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.
pod 'Contentful', '0.2.3'
To learn more about operators for dependency versioning within a Podfile, see the CocoaPods doc on the Podfile.
Note that for Swift 2.3 support (contentful.swift v0.2.3) you will need to add a post-install, configuration change to Pods.xcodeproj. You can do this via the Podfile:
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
License
Copyright © 2016 Contentful GmbH. See LICENSE for further details.
View on GitHub
Contentful Reference