小编Nah*_*han的帖子

如何修复'不能在不可变值上使用变异成员'?

得到错误:

错误:不能在不可变值上使用变异成员:'fromArray'是'let'常量

在以下代码中:

func removing (item: Int, fromArray: [Int]) -> [Int] {

    for i in 0...fromArray.count-1 {
        if fromArray[i] == item {
            let index = i
            fromArray.remove(at: index) // <-- error is here
        }
    }
    return fromArray
}

var anarray : [Int] = [1, 2,3, 4 ,3]
var x = 3
removing(item: x, fromArray: anarray)
Run Code Online (Sandbox Code Playgroud)

swift

6
推荐指数
4
解决办法
1万
查看次数

如何将音频流 URL 设置为 AVAudioFile?

我正在关注本教程:https : //miguesaldana.me/2017/03/13/how-to-create-a-soundcloud-like-waveform-in-swift-3/

我的代码如下。有一个例外:

错误域=com.apple.coreaudio.avfaudio Code=2003334207 “(null)” UserInfo={failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)}

   let file = try! AVAudioFile(forReading: AudioLink)  //Got Exception Here

    let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: file.fileFormat.sampleRate, channels: file.fileFormat.channelCount, interleaved: false)
    print(file.fileFormat.channelCount)
    let buf = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: UInt32(file.length))
    try! file.read(into: buf!)



    //     print("floatArray \(readFile.arrayFloatValues)\n")
    //self.waveFormView.setNeedsDisplay()
Run Code Online (Sandbox Code Playgroud)

avfoundation ios swift swift3

5
推荐指数
0
解决办法
484
查看次数

标签 统计

swift ×2

avfoundation ×1

ios ×1

swift3 ×1