在NSData对象上使用getBytes时遇到问题。这是代码:
if let blobBase64DecodedData = blob.base64DecodedData() {
var URILength: UInt8 = 0
if blobBase64DecodedData.count > 0 {
let uriLengthRange: Range<Int> = 1..<3
let testData = (blobBase64DecodedData.subdata(in: uriLengthRange) as NSData)
(blobBase64DecodedData.subdata(in: uriLengthRange) as NSData).getBytes(&URILength, length: MemoryLayout<UInt8>.size)
let uriDataRange: Range<Int> = 2..<(2+Int(URILength))
let sURIData = blobBase64DecodedData.subdata(in: uriDataRange) <—CRASH HERE
// further processing
}
}
问题是uriDataRange比blobBase64DecodedData对象中的大。因此我认为getBytes存在问题,其中URILenght被赋予一个值。有谁知道问题是什么? GetBytes究竟做了什么?
由于