小编Aar*_*ron的帖子

使用目标c中的完成处理程序调用Swift函数

我试图在目标C类中调用包含完成处理程序的Swift函数,但我不确定如何实现它.

这是我的Swift Code

@objc class textToSpeech:NSObject{

func toSpeech(word: NSString, sucess:()->Void) -> NSURL {
    let tempDirectory = NSURL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
    let tempFile = tempDirectory.URLByAppendingPathComponent((word as String) + ".wav")

    let tts = TextToSpeech(username: "xxxxxx", password: "xxxxxx")
    tts.synthesize(word as String,
               voice: SynthesisVoice.GB_Kate,
               audioFormat: AudioFormat.WAV,
               failure: { error in
                print("error was generated \(error)")
}) { data in

        data.writeToURL(tempFile, atomically: true)
        print("createdURL")
        print(tempFile)
        sucess();

}

return tempFile
}
Run Code Online (Sandbox Code Playgroud)

我如何在目标c中编写函数调用.我已经完成了项目的设置,因此我可以从目标c调用swift函数.

asynchronous objective-c callback swift

3
推荐指数
1
解决办法
1037
查看次数

标签 统计

asynchronous ×1

callback ×1

objective-c ×1

swift ×1