简体   繁体   English

如何从Swift类访问Freestreamer Objective C类?

[英]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. 我对iOS开发完全陌生,因此决定直接从新的Swift编程语言开始。 But some Objective C knowledge is needed though, so this is a very basic question! 但是,尽管需要一些Objective C知识,所以这是一个非常基本的问题!

I am trying to use the FreeStreamer library , to play a shoutcast stream in my iOS app. 我正在尝试使用FreeStreamer库 ,在我的iOS应用中播放一个shoutcast流。 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? 我遵循了基本步骤(在Xcode项目中复制了所需文件),但是如何从Swift类访问FSAudioStream?

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. 但是没有找到FSAudioStream类,这不足为奇。 Should I add an extra import to my file? 我应该在文件中添加额外的import吗? In that case, which one? 在那种情况下,哪个?

Ok, I found the solution from this Apple Developer page on mixing Swift and Objective C . 好的,我从Apple开发人员页面上找到了将Swift和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. 但是有一点很重要:在项目的“快速编译器-代码生成”部分中设置“ Objective-C桥接标头”时, 通常必须设置路径,从而依次设置“调试”和“释放”键。

So I set the "Swift Compiler - Code Generation" parameter to MyProject/MyProject-Header.h . 因此,将“ Swift Compiler-Code Generation”参数设置为MyProject/MyProject-Header.h

And in the MyProject/MyProject-Header.h file I added this: MyProject/MyProject-Header.h文件中,我添加了以下内容:

#import "FSAudioStream.h"

And then there is nothing to import in the Swift file. 然后,没有任何要导入的Swift文件。

Problem solved! 问题解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM