Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 UInt8 数组,其中包含 0 到 255 之间的值
我想将此数组转换为 Int8 数组以包含 -128 和 127 之间的值
如何快速实现这一目标?
使用map和适当的初始化程序:
map
let intArray = uintArray.map { Int8(bitPattern: $0) }
您可以使用以下方法将 [UInt8] 转换为 [Int8]:
for el in uint8Array { uint8Array.append(UInt8(bitPattern: el)) }