mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 20:48:59 +00:00
[Swift] Rebuild the way swift handles structs from scratch (#6326)
* Rebuild the way swift handles structs from scratch * Updates docs, and sample binary * Replaces InMemory to Mutable * Migrates docs from inmemory * use inline for some functions * Renamed Mutable objects * Updates documentation
This commit is contained in:
@@ -64,7 +64,8 @@ Now you can access values like this:
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
|
||||
let hp = monster.hp
|
||||
let pos = monster.pos
|
||||
let pos = monster.pos // uses native swift structs
|
||||
let pos = monster.mutablePos // uses flatbuffers structs
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -76,8 +77,10 @@ In some cases it's necessary to modify values in an existing FlatBuffer in place
|
||||
if !monster.mutate(hp: 10) {
|
||||
fatalError("couldn't mutate")
|
||||
}
|
||||
// mutate a struct field
|
||||
let vec = monster.pos.mutate(z: 4)
|
||||
// mutate a struct field using flatbuffers struct
|
||||
// DONT use monster.pos to mutate since swift copy on write
|
||||
// will not mutate the value in the buffer
|
||||
let vec = monster.mutablePos.mutate(z: 4)
|
||||
|
||||
// This mutation will fail because the mana field is not available in
|
||||
// the buffer. It should be set when creating the buffer.
|
||||
|
||||
Reference in New Issue
Block a user