我有一个用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