How to import a project into Xcode - ios

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!

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)

Related

How to add Firebase Functions v8 to a Swift iOS project and use Codable in httpsCallable?

I have a Swift 5.5 iOS project that already contains Firebase 7.x and uses Firebase Functions. I just upgraded to 8.13.0, because I want to use Codable support in Firebase Functions.
I added Firebase through the Swift Package manager and included Firebase Functions in my source code using:
import FirebaseFunctions
However, when I want to call:
func httpsCallable<Request: Encodable,
Response: Decodable>(_ name: String,
requestAs: Request.Type = Request.self,
responseAs: Response.Type = Response.self)
I get an error saying that it doesn't find this method.
Upon inspecting the packages, I discovered that the function I want to call is defined in FirebaseFunctionsSwift in a file called Callable+Codable .
This exists in my project as you can see:
However when I add import FirebaseFunctionsSwift to my source file I get the following error:
No such module 'FirebaseFunctionsSwift'
How can I solve this problem?
Add FirebaseFunctionsSwift-Beta framework to the build target:

Syntax errors in Lyft API for iOS - won't compile?

I am trying to use the Lyft API for iOS with Swift 4 and Xcode 9.3.
When I use the pod LyftSDK, the framework files do not compile per this issue, which I fixed (but it seemed bizarre that a major API would not compile in a production build). It's currently an open issue on the Lyft-iOS-SDK GitHub, #17. I'm also using the pod Lyft because I was unsure of which to use.
In my view controller, I've imported:
import Lyft
import LyftSDK
But then when I go to use let lyftButton = LyftButton() I get the compilation error Use of unresolved identifier 'LyftButton'.
How do I use this API with Swift? Do I need both pods for it to work? I'm following the documentation line for line and can't get it to work how it's supposed to. None of the other APIs and CocoaPods I'm using have this issue.
I solved this by doing the following:
In LyftSDK/Core/LyftButton.swift, change Line 47 from private var pressUpAction: ((Void) -> Void)? to private var pressUpAction: (() -> Void)?.
In LyftSDK/Core/LyftAPIURLEncoding.swift, replace Line 32 with:
var localVariable = urlComponents
urlComponents?.queryItems = (localVariable?.queryItems ?? []) + queryItems

CGDataProviderCreateWithCFData function not recognized in Xcode IOS

I am looking at a camera tutorial for IOS and the CGDataProviderCreateWithCFData function was used. However Xcode doesn't seem to recognize it. Was this function removed from the latest Xcode Swift update? I am using Xcode version 8.1 and Swift 3. Also I have the following imports:
import UIKit
import AVFoundation
Have you tried searching "CGDataProviderCreateWithCFData" in the Apple's API reference page?
When I tried, I was guided to the Objective-C page, and its Swift link shows:
Initializer
init(data:)
Creates a data provider that reads from a CFData object.
In Swift 3, CGDataProviderCreateWithCFData is imported as an initializer of CGDataProvider and use it as:
let dataProvider = CGDataProvider(data: imageData as CFData)
(Assuming imageData as a Data.)
You can use it with import UIKit.

Create iOS framework using swift

I am trying to create an iOS framework using swift. I follow this blog and also few others but the output is not the way I want.
Below is my original source file
public class TestClass: NSObject {
// publicVar description
public var publicVar: Int = 0
// doSomething description
public func doSomething() {
print("doSomething method")
}
}
After adding the framework into my project it's create an TestFramwork-Swift.h
You can see it's not contain my description. I want the framework
header files like Apple.
Can anyone help me to figure out this. I am not able to understand where I am doing wrong. I am also not able to add more swift files into my framework.
Just use triple slash instead of double slash for comments you want to show in your framework headers.

How to access a Freestreamer Objective C class from Swift class?

I am totally new to iOS development, and I decided to start directly with the new Swift programming language. But some Objective C knowledge is needed though, so this is a very basic question!
I am trying to use the FreeStreamer library, to play a shoutcast stream in my iOS app. I followed the basic steps (copied among others the needed file in my Xcode project) but how can I access to the FSAudioStream from my Swift class?
I tried this:
import UIKit
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let test = FSAudioStream
}
// ...
}
But the FSAudioStream class is not found, which doesn't surprise me. Should I add an extra import to my file? In that case, which one?
Ok, I found the solution from this Apple Developer page on mixing Swift and Objective C.
But there was something important: when setting the "Objective-C Bridging header" in the "Swift Compiler - Code Generation" section of the project, the path has to be set generally which in turns set value for both the "Debug" and "Release" keys.
So I set the "Swift Compiler - Code Generation" parameter to MyProject/MyProject-Header.h.
And in the MyProject/MyProject-Header.h file I added this:
#import "FSAudioStream.h"
And then there is nothing to import in the Swift file.
Problem solved!

Resources