Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Getting Started with Data

Getting Started with Data

Using the data store provided by Telerik Platform begins with creating a content type. Content types are sets of data items that have a similar structure.

By creating a content type you are also defining a RESTful service layer that you can consume in the client app. The iOS SDK wraps the RESTful layer to help you consume data more easily and with less lines of code.

In this article you will learn how to create a content type in Telerik Platform and how to connect an iOS app to it.

Steps at a glance:

  1. Create a Content Type
  2. Add Fields
  3. Create Your First Data
  4. Get the App ID for Your App
  5. Add the SDK to a New or Existing Project
  6. Create a Model for Your Data
  7. Initialize the Everlive Instance
  8. Connect to Your Data

Prerequisites

Create a Content Type

Open your Telerik Platform app and navigate to Data > Types. Click the Create a Content Type button.

Create types overview image

Add Fields

You will see the Create a content type dialog. Enter a name for your content type, for example Places.

Each content type has predefined fields in its structure for better administration of the data. You can extend the structure of a content type with additional fields. When you finish defining or editing the structure of a type, click the Save button. You will see the data browser screen for the newly created content type.

Create a content type and fields image

Create Your First Data

You can create your first data item directly from the UI portal. Ensure that the data browser is showing your newly created content type and then click the Add an Item button. Fill in the input fields on the right. Click Save when you are ready.

Create a data item image

Get the App ID for Your App

The App ID is the unique identifier of your Telerik Platform app. You can find it in Settings. It is needed to connect your client app to your Telerik Platform data store.

Get the App ID of your App

You are now ready to connect your client app to data using the various Backend Services client SDKs.

Download the SDK

Open your Telerik Platform account and navigate to the Getting Started > Downloads screen in the top right corner. Click Backend Services to see a list of all available downloads. Choose your desired platform and download the ZIP archive to your local machine.

Downloads overview image

Add the SDK to a New or Existing Project

Unzip the archive with the SDK and include the SDK in your project.

Add the following statement to reference the SDK:

#import <EverliveSDK/EverliveSDK.h>

If you are working in a Swift project you need to add a bridging header to your project from Xcode by choosing File - New - File - iOS - Source - Header. Then add the statement above to the header. Register the bridging header under Build Settings > Swift Compiler > Code Generation with the relative path to the header, for example "MyBridgingHeader.h".

Create a Model for your Data

First, you need to create a model representing the server entity. Create a new Place class and construct the model as follows:

Create a Header File in Objective-C

#import <EverliveSDK/EverliveSDK.h>

@interface Place : EVObject
@property (nonatomic, strong) NSString *country;
@end

Create an Implementation File in Objective-C

#import "Place.h"

@implementation Place
+ (NSString *)description
{
return @"Places";
}
@end

Import the Model Class

Import a reference to the header file of the newly-created model class in the bridging header.

#import "Place.h"

For Swift projects you need to add it to the bridging header.

Initialize the Everlive Instance

Initialize the Everlive instance in the entry point of your application in the following manner.

[Everlive setApplicationKey:@"your-app-id"];
let myAppId:String = "your-app-id"

Everlive.setApplicationKey(myAppId)

By default all server requests are transmitted over HTTP. To use HTTPS, set the UseHTTPS key to true in your .plist file or in the Custom iOS Target Properties.

Connect to Your Data

The following snippet retrieves all items from the specified content type.

 [Place fetchAll:^(NSArray *result, NSError *error) {
    if (error != nil) {
        NSLog(@"Unfortunately an error occurred: %@", error.domain);
    } else {
        for (int index = 0; index < [result count]; index++)
        {
            Place *place = [result objectAtIndex:index];
            NSLog(@"The place's country is: %@", place.country);
        }
    }
}];
Place.fetchAll {(places:Array!, error:NSError!) -> Void in
    if(error != nil) {
        println("Unfortunately an error occurred: " + error.domain)
    } else {
        for item in places {
            var place = item as Place
            println("The place's country is: '\(place.country)'")
        }
    }
}

See Also

Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.