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.
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)!")
}
}
The EntryModellable
protocols allows you to define types that will be mapped from Entry
s 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.
For further information about the API, check out the Content Delivery API Reference Documentation.
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.2 ] |
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 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.2'
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
You can also use Carthage for integration by adding the following to your Cartfile
:
github "contentful/contentful.swift" ~> 0.9.0
Copyright (c) 2016 Contentful GmbH. See LICENSE for further details.