Flurry Integration Using Swift

If you prefer to develop iOS apps using Swift and want to integrate Flurry Analytics in your Xcode project, you can accomplish this task with a few simple steps outlined in this guide.

To make this happen, you’ll import a set of Objective-C files in the same app target as your Swift code and use an Objective-C bridging header to expose those files to Swift.

Important

These instructions will only guide you in integrating Flurry Analytics. If you plan on also integrating Flurry Ad Publishing for a Swift project, follow “Option 1” on the iOS Integration Page and import Flurry using Cocoapods.

A screencast of the process illustrates the steps to follow. The entire integration should take no longer than ten minutes.

What You Need

For starters, you’ll need to download and install the Flurry SDK on your system.

If you haven’t, follow these links:

  1. Create an account and
  2. Create an app for iPhone.

Once you download the Flurry SDK and obtain your API keys, you’ll be ready to start a Flurry Session.

Set Up

Set up is easy and straightforward. Follow these steps:

  1. Create a Swift-based app from one of the Xcode templates.
  2. In your Xcode project, select File > Add Files to “demonstration”, navigate to your Flurry SDK and add the following files:
  • Flurry.h
  • libFlurry_6.x.x.a

Important: Make sure you’ve checked the Copy Items if needed checkbox under the Destination section.

destination checked
  1. In your project, select Build Phases.
  2. Click the + symbol and add the following frameworks to your project:
  • Security.framework
  • SystemConfiguration.framework

Important: Although these frameworks are not required for simple Flurry analytics integration, you’ll need them in order to display ads in your apps.

frameworks added

Configure Bridging Header File

Follow these steps:

  1. Select your demonstration project subfolder.
  2. Select File > New > File.

You’ll be prompted to choose a template for your new file, which we will select Source under iOS along with Header File.

  1. When prompted to save the file, name it using the following convention:

projectname-Bridging-Header.h, where projectname is the name of your project (in this case, it’s integration).

  1. Select your project root and select Build Settings.
  2. In the search bar, type in Swift Compiler.
  3. In the “Objective-C Bridging Header” section, double-click the empty space.

You’ll be prompted to enter a path to the bridging header file that you want to expose.

bridging header path
  1. Enter projectname/projectname-Bridging-Header.h.
  2. In your “projectname-Bridging-Header.h” file, import Flurry.h:
  1. Finally, in your AppDelegate.swift file, start typing Flurry.
  2. Success!

Now you can import Flurry methods written in Objective-C and use them in our Swift apps. If you need any other files for development, simply import them in projectname-Bridging-Header.h.

Get Started With Flurry Analytics

Now that you’ve got your bridging header set up and can import existing Objective-C code, you can begin working with Flurry analytics.

First, let’s create a Flurry Session:

flurry session

Replace “YOUR_API_KEY” with the API key you received when registering your app through Flurry’s Developer website.

To log events, it’s as simple as this:

flurry events

where you can replace Started Application with any string of your choice.

Move on to Tracking Custom Events

Following the steps in this guide, you’ve successfully integrated Flurry SDK using Swift and are now ready to move on to Tracking Custom Events. In doing so, you’ll be better able to understand many facets of user behavior in your apps.