/FlatBuffersSwift

Infrastructure for FlatBuffers, contains a reader and a builder

Primary LanguageSwiftMIT LicenseMIT

FlatBuffersSwift

Join the chat at https://gitter.im/mzaks/FlatBuffersSwift

Motivation

This project brings FlatBuffers (an efficient cross platform serialization library) to Swift.

One minute introduction

There are three simple steps for you to use FlatBuffersSwift

1. Write a schema file

table List {
  people : [Person];
}

table Person {
  firstName : string;
  lastName : string;
}

root_type List;

2. Generate Swift code

java -jar fbsCG.jar -fbs contacts.fbs -out contacts.swift -lang swift

3. Use the generated API

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

Please check out Wiki for more information.