Search code examples
iosxcodeswiftimportyelp

How to import a project into Xcode


I am attempting to integrate the Yelp API into my iOS app. From the existing yelp documentation for objective C, we downloaded their Xcode project and dragged it into our project. However, when trying to call and import the project in my swift file, we have errors. Here is what I mean:

func getYelpData(mapItem:MKMapItem) {
    var term: String = (NSUserDefaults.standardUserDefaults().valueForKey("term") ?? "") as! String;

    var location: String = (NSUserDefaults.standardUserDefaults().valueForKey("location") ?? "") as! String
    var APISample: YPAPISample = YPAPISample() // Use of undeclared type 'YPAPISample'

and at the top of the class I try to import the YPAPISample like so

import YelpAPISample

but it does not allow me to do this either.

I'm new to swift programming so any help would be greatly appreciated!


Solution

  • It's one of the most regularly asked question regarding Swift on SO.

    Apple provided a document here for such purpose:

    https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

    In short, you'd need to create a bridge header to import the Objective-C framework. Not all the framework can be import directly in Swift.


    To add it manually, search bridging in build settings: (Make sure you select All)

    enter image description here