Kentico Cloud Swift SDK
The KenticoCloud iOS SDK is a library used for retrieving content. You can use the SDK as a CocoaPod package or add it manually.
Sample app
The repository contains sample app which demonstrates basic usage of the SDK.
Quick start
1. Add a pod
2. Create a type object - in this example, the type object is Article
. It represents a Content type in Kentico Cloud that the retrieved content items are based on. This content type has three elements with following codenames: title
(a text element),teaser_image
(an asset element) and post_date
(a DateTime element).
3. Prepare the Delivery client
4. Prepare a query
5. Get and use content items
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
To integrate KenticoCloud into your Xcode project using CocoaPods, specify it in your Podfile
:
Then, run the following command:
Using the DeliveryClient
The DeliveryClient
class is the main class of the SDK for getting content. Using this class, you can retrieve content from your Kentico Cloud projects.
To create an instance of the class, you need to provide a project ID:
Once you create a DeliveryClient
, you can start querying your project repository by calling methods on the client instance. See Basic querying for details.
Previewing unpublished content
To retrieve unpublished content, you need to create a DeliveryClient
with both Project ID and Preview API key. Each Kentico Cloud project has its own Preview API key.
For more details, see Previewing unpublished content using the Delivery API.
Getting content from secured project
To retrieve content from secured project, you need to create a DeliveryClient
with both Project ID and Secure API key.
For more details, see Securing the Delivery API.
Getting items
Using strongly typed models
In order to receive strongly typed items you need to implement your item model. It's necessary to conform to Mappable
protocol and implement mapping functionality. You can use your own mapping or our strongly typed element types.
- Element types mapping:
- Custom mapping:
Basic items querying
Once you have a DeliveryClient
instance, you can start querying your project repository by calling methods on the instance. You need to pass your item model and query. You can create a query for a listing in two ways:
- creating a custom string query:
- using a query parameters array:
Then you can use your obtained items in the completetion handler:
You can also retrieve just a single item:
Getting linked items
You can get linked content items from itemResponse
or itemsResponse
object:
Getting content types
Get one content type
Get multiple content types
Getting taxonomies
Get taxonomy group
Get all taxonomies
Local Development
For running SDK with sample app locally follow the next steps.
- Download the repository.
- In terminal navigate to /Example.
- Run
pod install
(Cocoapods must be installed). - Open
KenticoCloud.xcworkspace
in XCode. - Run.
Debug
If you want to view debug info from both clients set client's enableDebugLogging
attribute:
Updating generated documentation
We use Jazzy which is a command-line utility that generates documentation for Swift. For updating documentation perform the next steps:
- Install Jazzy
[sudo] gem install jazzy
- Run
jazzy
from the root of the repository. - Commit changes from /Docs directory.