我有一個用Objective-C編寫的函數,我想將它轉換爲Swift,但我不斷收到錯誤。將Objective-C塊轉換爲Swift
下面是Objective-C代碼:
- (void)openFileWithFilePathURL:(NSURL*)filePathURL
{
self.audioFile = [EZAudioFile audioFileWithURL:filePathURL];
self.filePathLabel.text = filePathURL.lastPathComponent;
//
// Plot the whole waveform
//
self.audioPlot.plotType = EZPlotTypeBuffer;
self.audioPlot.shouldFill = YES;
self.audioPlot.shouldMirror = YES;
//
// Get the audio data from the audio file
//
__weak typeof (self) weakSelf = self;
[self.audioFile getWaveformDataWithCompletionBlock:^(float **waveformData,
int length)
{
[weakSelf.audioPlot updateBuffer:waveformData[0]
withBufferSize:length];
}];
}
這裏是我的銀行代碼:
func openFileWithFilePathURL(url: NSURL) {
let audioFile = EZAudioFile(URL: url)
audioPlot.plotType = EZPlotType.Buffer
audioPlot.shouldFill = true
audioPlot.shouldMirror = true
audioFile.getWaveformDataWithCompletionBlock({(waveformData, length) in
audioPlot.updateBuffer(waveformData[0], withBufferSize: length)
})
}
,我總是得到
Command failed due to signal: Segmentation fault: 11
我是新的錯誤到iOS語言,我花了幾個小時在這個問題上。我真的不知道如何解決這個問題。
我想問題在於我如何將塊從Objective-C轉換爲Swift。
謝謝你的幫助!
https://github.com/syedhali/EZAudio/issues/198 –
http://stackoverflow.com/questions/31305488/how-to- write-block-with-arg-unsafemutablepointerunsafemutablepointerfloat –
根據我的經驗,錯誤(分段錯誤)是Xcode本身的一個錯誤,當它在實際有效的語法中窒息時。我通常嘗試編譯不同的語法變體,直到它工作。 – paulvs