Skip to content

Instantly share code, notes, and snippets.

@koji
Created January 11, 2015 18:31
Show Gist options
  • Save koji/87c75d340590f672701f to your computer and use it in GitHub Desktop.
Save koji/87c75d340590f672701f to your computer and use it in GitHub Desktop.
How to import or use Objective-C library with Swift
When I tried to use Parse SDK with swift, I just noticed how did I use Parse SDK with swift.
First, I tried to code like Objective-C. Of course, it didn’t work and it only displayed some error, “You can’t do that because you have to import Parse SDK.” After that I googled and did try & error. Finally, I could use Parse SDK with swift. So I’m gonna show you how to use Objective-C library with Swift.
Step1. Create a header file
[Create New file]-[Header file] At that time, you have to name “ProjectName-Bridging-Header.h.” It’s a rule.
If your project name is “ParseTest”, you have to name “ParseTest-Bridging-Header.h”.
Step2. Add Parse header file path
If you finish step1 well, Xcode will create the file like below
#ifndef Mukai_Mukai_Bridging_Header_h
#define Mukai_Mukai_Bridging_Header_h
#endif
If you can see above codes, you just put Parse header file path.
#ifndef Mukai_Mukai_Bridging_Header_h
#define Mukai_Mukai_Bridging_Header_h
#import <Parse/Parse.h>
#endif
Step3. Set the file path
It’s almost done. Finally, you have to set the file path.
[Build Setting]-[Swift Compiler]-[Objective-C Bridging Header]
You should like below
http://i.stack.imgur.com/8LiwF.gif
That’s it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment