This project brings FlatBuffers (an efficient cross platform serialization library) to Swift.
There are three simple steps for you to use FlatBuffersSwift
table List {
people : [Person];
}
table Person {
firstName : string;
lastName : string;
}
root_type List;
java -jar fbsCG.jar -fbs contacts.fbs -out contacts.swift -lang swift
Create objects and write them to file
let p1 = Person(firstName: "Maxim", lastName: "Zaks")
let p2 = Person(firstName: "Alex", lastName: "Zaks")
let list = List(people: [p1, p2])
let fbData = list.toByteArray
NSData(bytes: UnsafePointer<UInt8>(fbData), length: fbData.count).writeToFile("list.bin", atomically: true)
Read data from file very efficiently (no parsing, lazy instantiation)
let lazyList = List.LazyAccess(data: UnsafePointer((NSData(contentsOfFile: "list.bin")?.bytes)!))
let name = lazyList.people[0]?.firstName