【发布时间】:2021-01-21 19:55:55
【问题描述】:
首先:我真的想将数组保存为.txt 文件。 .plist 是不可能的。
原因:之后我想使用 C++ 将它保存到向量中。用包装器意识到这一点已经让我发疯了。
这是我的代码:
guard let buf = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: AVAudioFrameCount(file.length))
else{ throw NSError()}
try file.read(into: buf)
guard buf.floatChannelData != nil else{print("Channel Buffer konnte nicht erstellt werden")
throw NSError()}
let samples = Array(UnsafeBufferPointer(start:buf.floatChannelData![0],count:Int(buf.frameLength)))
var wData = Data(samples)
try! wData.write(to: outputURL())
但是不可能用浮点值初始化数据,不是吗?
如何将浮点值数组写入.txt 文件?
【问题讨论】:
-
为什么不直接使用
JSONEncoder对其进行编码? -
你也可以保存它的原始字节
-
@LeoDabus 我还没有与 JSON 编码器有任何联系。应该怎么做呢?