简体   繁体   中英

swift 5 data.withUnsafeBytes

Swift 4 code:

self.dataArray = data.withUnsafeBytes {
                    [UInt16](UnsafeBufferPointer(start: $0, count: data.count))
                }

From looking at other answers to similar problems, I changed the above to:

self.dataArray = data.withUnsafeBytes {$0.load(as: [UInt16].self)}

The code compiles but gives me an exception: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

Any ideas? Thanks

感谢 Martin R。我的问题的答案是:

data.withUnsafeBytes{ Array($0.bindMemory(to: UInt16.self))}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM