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
}
}