You will be asked to configure a bridging header file - click Yes. An .h file will be created following the naming convention: YourProjectName-Bridging-Header. Include the following lines in that file:
#import <UIKit/UIKit.h>
#import
<TelerikUI/TelerikUI.h>
var chart =
TKChart
(frame:
CGRectInset
(
self
.view
.bounds
,
30
,
30
))
self
.view
.addSubview
(chart)
Everything is similar to Objective-C, you can use all Cocoa Touch frameworks and APIs. The named parameters are also here, but there are fewer braces and no semicolons :)
In order to show the chart, we should add some data. The following lines will create a simple sine wave:
var
items
: [
TKChartDataPoint]
= []
for
x in
0
.
.<10
{
var y =
100
.0
*
sin
(
M_PI
*
CDouble
(x) +
100
.0
)
items
.append
(
TKChartDataPoint
(x:
CDouble
(x +
x
*
3
),
y
:y))
}
As you can see even constants like M_PI are available. Its interesting that you can change the (..)two dots in the for cycle with (...)three dots. This way you will include also the final value when iterating.
You should create a series in order to add this data in the chart:
var series =
TKChartSplineSeries
(items:items)
series
.yAxis
=
TKChartNumericAxis
(minimum:-
100
,
andMaximum
:
100
)
var xAxis =
TKChartNumericAxis
(minimum:
0
,
andMaximum
:
20
)
xAxis
.majorTickInterval
=
5
series
.xAxis
= xAxis
chart
.addSeries
(series)
And the result is here:
The full sample code is available on our git repository.
You can download Telerik UI for iOS here.
So, this is it. Using Swift is really easy and intuitive.
Nikolay Diyanov Diyanov is the Product Manager of the Native Mobile UI division at Progress. Delivering outstanding solutions that make developers' lives easier is his passion and the biggest reward in his work. In his spare time, Nikolay enjoys travelling around the world, hiking, sun-bathing and kite-surfing.
Find him on Twitter @n_diyanov or on LinkedIn.