If you're like me, you've probably already started writing a Swift application to start learning the new language and to get familiar with what it provides. As you are writing the Swift app, you will quickly find that you will need to use an Objective-C framework, but where do you start? This blog post aims to show you how to use the Telerik UI for iOS in your next Swift app in just a few minutes.
Begin by creating your Swift Application or using an existing one. In the screenshot provided below, I’ve created a project and gave it a name, as well as switched the language to Swift.
Once the project is created, select “Linked Frameworks and Libraries” and hit the + button as shown below then, add in TelerikUI.framework. Note: This assumes that you have already downloaded and installed UI for iOS.
Now that we have the TelerikUI.framework added to our project, we need to simply add an “Empty Objective-C File” to our project. Go to File -> New -> File and select Objective-C File as shown below:
It will prompt you for a filename, and you can give it any name you want. Leave the File type as Empty File and press next.
It will ask you where to save it, so leave the default location as is in the next dialog. Finally, you will see this prompt appear: “Would you like to configure an Objective-C bridging header?”
Select “Yes” on this screen, and you will notice your Swift project now has two files:
Inside the .m file, you will see that it already added some comments and a reference to the Foundation framework. You can leave this file as is.
Inside the .h file, they’ve left a comment that says the following: “Use this file to import your target's public headers that you would like to expose to Swift.” Here we are going to add two lines:
The first is to a required framework for Telerik UI for iOS, and the second import statement is for the UI for iOS Framework.
We can now switch over to our ViewController.swift or whatever file we would like to use the Telerik framework in and add some code. In this sample, I’m going to create a simple chart to make sure my project has recognized that I’ve added UI for iOS.
I'll test it with the source code provided here.
Success! My app is using UI for iOS successfully in a Swift Application.
You are now ready to begin using our controls in your next Swift app!
FYI: If you happen to delete the bridging header, you will need to create an .h file and go to the plist project file and set the appropriate bridging header name.
I hope this post gave you a look at how easy it is to useTelerik UI for iOS in your next Swift Application. While I only covered the chart, this can be applied to all of our controls such as ListView, DataForm, Alert, Calendar, SideDrawer and more! Feel free to download a trial of Telerik UI for iOS and checkout our new DataForm and Alert controls. I should also mention, that our documentation has complete samples for all of our controls in Swift as well as Objective-C, so use what language is best for you and your team.
Thanks for reading and if you have any questions, then feel free to leave a comment below.
Michael Crump is a Microsoft MVP, Pluralsight and MSDN author as well as an international speaker. He works at Telerik with a focus on everything mobile. You can follow him on Twitter at @mbcrump or keep up with his various blogs by visiting his Telerik Blog or his Personal Blog.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.