Mobile SDK - Building the Bridge from Swift to Objective C

The Mobile SDK web doc points users to the Swiftilicio.us tutorial on installing Pods and creating the Objective C bridging header file. The tutorial glosses over a few steps that might not be obvious to new users, as they were not for me, so here is a more detailed tutorial that I hope you fund useful. The screen shots are hard to read in post, so click the expand arrow at the bottom of the image to blow them up.

First, open your Swift project by clicking on the projectName.xcworkspace file.

Next, File -> New -> File IOS Source Header file

Chose Next, then fill in the options show here.
Save As -> Bridging-Header.h
Group, navigate to the project name folder that contains the file ViewController.swift

When you have successfully created the Bridging-Header.h file and it is in the right location, your project folder view will look like this:

Now, click on the top level item with your project name (blue folder beside it) . You will see the build settings page. It will come up with whatever view options you last closed it with, so if you have not opened it before it may look like this. In the search bar upper right, if you type 'sw' it will filter as shown. Note that under Swift Compiler there is no option to add an Objective C bridge file.

To the right of the work PROJECT, note the four choices: Basic, All, Combined and Levels. In the startup default settings Basic and Combined will be dark blue. You must click on All and Levels so they are dark blue, and then the Build Settings - Swift Compiler Code Generation options will look like this.

Look at the screen shot below. Note the box with the arrow on top. You open this box by double clicking on the line that is highlighted (Objective-C Bridging Header) directly above where the arrow is. Clic too far away from that arrow and the box will not open up. When the box opens up, it will be empty. Add the line shown below, substituting your path and header file name. YourProjectName/Bridging-Header.h Then hit enter to save it.

Now that line will look like below. If it does not, work at it till it does.

Now you must edit the User Header Search Path and add the path Pods and make it Recursive. To do that, first change the filter in the search bar (upper left) to 'search'. Then on the line User Header Search Path, where the arrow above the box is, double click to open the box. In the lower left of the box is a plus sign. Click it to add a line that you will fill in. Type the word Pods on the left as shown. Change the right side of the line from non-recursive (default) to recursive.

The last step is to edit the Bridging-Header.h file to include the reference to the SparkCloud.h file. The Objective C header file for the SparkCloud class. Open the file by clicking on it. Add the line #import "SparkCloud.h"

Now, you can open ViewController. swift by clicking on it. In the viewDidLoad() function, open some empty lines after the comment // Do any..., and before the curly brace.

Copy the swift code shown for the .loginWithUser method from this post, about 3/4 of the way down the post

When your ViewController.swift file looks like the one shown below, hit Build, and watch for the Logged in message in the console window. Or, if not logged in, the message "Wrong credentials...".

Success! Now start adding more snips of the example code and building Apps!

2 Likes

Thank you for the tutorial! It was a bit confusing to figure out using the docs on the website alone.

Hi!
I did everything you are telling in your tutorial!

My issue is when I compile!!

I get the following error :

Undefined symbols for architecture x86_64:
“OBJC_CLASS$_SparkCloud”, referenced from:
type metadata accessor for __ObjC.SparkCloud in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I was able to create my project and include both Park-SDK and Spark-Setup using cocoa pods!

My problem is when it’s time to compile I get the following error :smile:

Undefined symbols for architecture x86_64:
“OBJC_CLASS$_SparkCloud”, referenced from:
type metadata accessor for __ObjC.SparkCloud in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Someone can help me??

I was able to create my project and include both Park-SDK and Spark-Setup using cocoa pods!
I need help!!!

My problem is when it’s time to compile I get the following error :smile:

Undefined symbols for architecture x86_64:
“OBJC_CLASS$_SparkCloud”, referenced from:
type metadata accessor for __ObjC.SparkCloud in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Someone can help me??

Please don’t double post.
If you want to attract attention of people who helped in another thread you can ping them via via their member name like this @goncalo - or you only reply in the other thread, but not twice.

Anyone had the same issue I have?!?!

And even less triple post!

Here’s the same tutorial in a video version. @Bendrix really helped however the tutorial is a little hard to follow (i.e. file names are inconsistent and pictures don’t match instructions perfectly)

hello @demented , thanks for the tutorial saved a lot of time . i followed your tutorial and i landed up with this error .
Undefined symbols for architecture i386:
“OBJC_CLASS$_SparkCloud”, referenced from:
type metadata accessor for __ObjC.SparkCloud in ViewController.o
"OBJC_CLASS$_SparkDevice", referenced from:
type metadata accessor for __ObjC.SparkDevice in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

i see the above conversation but i dint see a solution for this error . @goncalo ,did you find any solution for the similar error that we have come across.

Hi gbabu012,

I just create a new project following both tutorials and everything worked like a charm.

thanks for the reply , i still see the issue even after i created a new project .

thanks!
giri

Just remember something.

Make sure that your pod file looks exactly like the one on the tutorial.
Mine, was not the same at the beginning and once I match it with the one on the tutorial, it worked.

@Bendrix

Thank you for this awesome tutorial. I just read your bios and realized you are the founder of Measurement Computing. I have used your products before and definitely like it.