无法推断出通用参数S.

时间:2017-05-09 08:00:18

标签: ios swift string encoding buffer

无法推断出通用参数S.

 var buff:[Int8] = [Int8](repeating:0,count:16)
 ...
 var addr = String(bytes: buff, encoding: String.Encoding.utf8)

How it seems in xCode

1 个答案:

答案 0 :(得分:3)

根据the documentationbuff需要为S : Sequence, S.Iterator.Element == UInt8的S类型。所以你需要它是一个UInt8的数组而不是Int8&#39>

import Foundation

var buff:[UInt8] = [UInt8](repeating:0,count:16)
var addr = String(bytes: buff, encoding: .utf8)