【问题标题】:Generic parameter S could not be inferred无法推断通用参数 S
【发布时间】:2017-05-09 08:00:17
【问题描述】:

无法推断通用参数 S。

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

How it seems in xCode

【问题讨论】:

    标签: ios swift string encoding buffer


    【解决方案1】:

    根据the documentationbuff 需要是 S 类型,其中S : Sequence, S.Iterator.Element == UInt8。所以你需要它是 UInt8 的数组而不是 Int8 的数组

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2015-09-22
      相关资源
      最近更新 更多