extension Array where Element 代码学习
Posted feng9exe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了extension Array where Element 代码学习相关的知识,希望对你有一定的参考价值。
var fieldNames: [String] {
let p = UnsafePointer<Int32>(self.pointer)
return Array(utf8Strings: relativePointer(base: p.advanced(by: 3), offset: self.pointer.pointee.fieldNames))
}
间接类型推断?!
---------------------------------------
protocol UTF8Initializable {
init?(validatingUTF8: UnsafePointer<CChar>)
}
extension String : UTF8Initializable {}
extension Array where Element : UTF8Initializable {
init(utf8Strings: UnsafePointer<CChar>) {
var strings = [Element]()
var pointer = utf8Strings
while let string = Element(validatingUTF8: pointer) {
strings.append(string)
while pointer.pointee != 0 {
pointer.advance()
}
pointer.advance()
guard pointer.pointee != 0 else {
break
}
}
self = strings
}
}
以上是关于extension Array where Element 代码学习的主要内容,如果未能解决你的问题,请参考以下文章