diff --git a/Package@swift-5.5.swift b/Package@swift-5.5.swift
index 3c2e13092..13313560e 100644
--- a/Package@swift-5.5.swift
+++ b/Package@swift-5.5.swift
@@ -32,6 +32,6 @@ let package = Package(
.target(
name: "FlatBuffers",
dependencies: [],
- path: "swift/Sources")
+ path: "swift/Sources"),
])
diff --git a/docs/source/SwiftUsage.md b/docs/source/SwiftUsage.md
index b10375e0b..c6116f6ae 100644
--- a/docs/source/SwiftUsage.md
+++ b/docs/source/SwiftUsage.md
@@ -72,7 +72,10 @@ Now you can access values like this:
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
- let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
+ var byteBuffer = ByteBuffer(bytes: data)
+ // Get an accessor to the root object inside the buffer.
+ let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
+ // let monster: Monster = getRoot(byteBuffer: &byteBuffer)
if !monster.mutate(hp: 10) {
fatalError("couldn't mutate")
diff --git a/docs/source/Tutorial.md b/docs/source/Tutorial.md
index 106931641..df08c1cae 100644
--- a/docs/source/Tutorial.md
+++ b/docs/source/Tutorial.md
@@ -2472,10 +2472,10 @@ myGame.Monster monster = new myGame.Monster(data);
~~~{.swift}
// create a ByteBuffer(:) from an [UInt8] or Data()
- let buf = // Get your data
-
+ var buf = // Get your data
// Get an accessor to the root object inside the buffer.
- let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
+ let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
+ // let monster: Monster = getRoot(byteBuffer: &byteBuffer)
~~~
diff --git a/grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift b/grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift
index cd0bc2338..4097defca 100644
--- a/grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift
+++ b/grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift
@@ -10,8 +10,6 @@ public struct models_HelloReply: FlatBufferObject, Verifiable {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsHelloReply(bb: ByteBuffer) -> models_HelloReply { return models_HelloReply(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -59,8 +57,6 @@ public struct models_HelloRequest: FlatBufferObject, Verifiable {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsHelloRequest(bb: ByteBuffer) -> models_HelloRequest { return models_HelloRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/grpc/examples/swift/Greeter/Sources/client/main.swift b/grpc/examples/swift/Greeter/Sources/client/main.swift
index 168b0713c..a4b2a675c 100644
--- a/grpc/examples/swift/Greeter/Sources/client/main.swift
+++ b/grpc/examples/swift/Greeter/Sources/client/main.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/grpc/examples/swift/Greeter/Sources/server/main.swift b/grpc/examples/swift/Greeter/Sources/server/main.swift
index fca623f5a..62286c475 100644
--- a/grpc/examples/swift/Greeter/Sources/server/main.swift
+++ b/grpc/examples/swift/Greeter/Sources/server/main.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/samples/monster_generated.swift b/samples/monster_generated.swift
index 79a6b384f..3be230371 100644
--- a/samples/monster_generated.swift
+++ b/samples/monster_generated.swift
@@ -4,7 +4,7 @@
import FlatBuffers
-public enum MyGame_Sample_Color: Int8, Enum {
+public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
public typealias T = Int8
public static var byteSize: Int { return MemoryLayout.size }
public var value: Int8 { return self.rawValue }
@@ -12,24 +12,29 @@ public enum MyGame_Sample_Color: Int8, Enum {
case green = 1
case blue = 2
-
public static var max: MyGame_Sample_Color { return .blue }
public static var min: MyGame_Sample_Color { return .red }
}
-public enum MyGame_Sample_Equipment: UInt8, Enum {
+
+public enum MyGame_Sample_Equipment: UInt8, UnionEnum {
public typealias T = UInt8
+
+ public init?(value: T) {
+ self.init(rawValue: value)
+ }
+
public static var byteSize: Int { return MemoryLayout.size }
public var value: UInt8 { return self.rawValue }
case none_ = 0
case weapon = 1
-
public static var max: MyGame_Sample_Equipment { return .weapon }
public static var min: MyGame_Sample_Equipment { return .none_ }
}
-public struct MyGame_Sample_Vec3: NativeStruct {
+
+public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
static func validateVersion() { FlatBuffersVersion_23_1_4() }
@@ -37,6 +42,13 @@ public struct MyGame_Sample_Vec3: NativeStruct {
private var _y: Float32
private var _z: Float32
+ public init(_ bb: ByteBuffer, o: Int32) {
+ let _accessor = Struct(bb: bb, position: o)
+ _x = _accessor.readBuffer(of: Float32.self, at: 0)
+ _y = _accessor.readBuffer(of: Float32.self, at: 4)
+ _z = _accessor.readBuffer(of: Float32.self, at: 8)
+ }
+
public init(x: Float32, y: Float32, z: Float32) {
_x = x
_y = y
@@ -52,6 +64,10 @@ public struct MyGame_Sample_Vec3: NativeStruct {
public var x: Float32 { _x }
public var y: Float32 { _y }
public var z: Float32 { _z }
+
+ public static func verify(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
+ try verifier.inBuffer(position: position, of: MyGame_Sample_Vec3.self)
+ }
}
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
@@ -70,14 +86,12 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
@discardableResult public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) }
}
-public struct MyGame_Sample_Monster: FlatBufferObject {
+public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable {
static func validateVersion() { FlatBuffersVersion_23_1_4() }
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Sample_Monster { return MyGame_Sample_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -104,16 +118,19 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
+ public var hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) }
public var color: MyGame_Sample_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Sample_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .blue }
@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
+ public var hasWeapons: Bool { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? false : true }
public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func weapons(at index: Int32) -> MyGame_Sample_Weapon? { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? nil : MyGame_Sample_Weapon(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func equipped(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
+ public var hasPath: Bool { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? false : true }
public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func path(at index: Int32) -> MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Sample_Vec3.self, offset: _accessor.vector(at: o) + index * 12) }
public func mutablePath(at index: Int32) -> MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 12) }
@@ -158,16 +175,35 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
MyGame_Sample_Monster.addVectorOf(path: path, &fbb)
return MyGame_Sample_Monster.endMonster(&fbb, start: __start)
}
+
+ public static func verify(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
+ var _v = try verifier.visitTable(at: position)
+ try _v.visit(field: VTOFFSET.pos.p, fieldName: "pos", required: false, type: MyGame_Sample_Vec3.self)
+ try _v.visit(field: VTOFFSET.mana.p, fieldName: "mana", required: false, type: Int16.self)
+ try _v.visit(field: VTOFFSET.hp.p, fieldName: "hp", required: false, type: Int16.self)
+ try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset.self)
+ try _v.visit(field: VTOFFSET.inventory.p, fieldName: "inventory", required: false, type: ForwardOffset>.self)
+ try _v.visit(field: VTOFFSET.color.p, fieldName: "color", required: false, type: MyGame_Sample_Color.self)
+ try _v.visit(field: VTOFFSET.weapons.p, fieldName: "weapons", required: false, type: ForwardOffset, MyGame_Sample_Weapon>>.self)
+ try _v.visit(unionKey: VTOFFSET.equippedType.p, unionField: VTOFFSET.equipped.p, unionKeyName: "equippedType", fieldName: "equipped", required: false, completion: { (verifier, key: MyGame_Sample_Equipment, pos) in
+ switch key {
+ case .none_:
+ break // NOTE - SWIFT doesnt support none
+ case .weapon:
+ try ForwardOffset.verify(&verifier, at: pos, of: MyGame_Sample_Weapon.self)
+ }
+ })
+ try _v.visit(field: VTOFFSET.path.p, fieldName: "path", required: false, type: ForwardOffset>.self)
+ _v.finish()
+ }
}
-public struct MyGame_Sample_Weapon: FlatBufferObject {
+public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable {
static func validateVersion() { FlatBuffersVersion_23_1_4() }
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsWeapon(bb: ByteBuffer) -> MyGame_Sample_Weapon { return MyGame_Sample_Weapon(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -196,5 +232,12 @@ public struct MyGame_Sample_Weapon: FlatBufferObject {
MyGame_Sample_Weapon.add(damage: damage, &fbb)
return MyGame_Sample_Weapon.endWeapon(&fbb, start: __start)
}
+
+ public static func verify(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
+ var _v = try verifier.visitTable(at: position)
+ try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset.self)
+ try _v.visit(field: VTOFFSET.damage.p, fieldName: "damage", required: false, type: Int16.self)
+ _v.finish()
+ }
}
diff --git a/samples/sample_binary.swift b/samples/sample_binary.swift
index 889bc980a..4df546fca 100644
--- a/samples/sample_binary.swift
+++ b/samples/sample_binary.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,8 +56,8 @@ func main() {
equippedOffset: axe)
builder.finish(offset: orc)
- let buf = builder.sizedByteArray
- let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
+ var buf = ByteBuffer(bytes: builder.sizedByteArray)
+ let monster: Monster = try! getCheckedRoot(byteBuffer: &buffer)
assert(monster.mana == 150)
assert(monster.hp == 300)
diff --git a/scripts/generate_code.py b/scripts/generate_code.py
index 1a8d2f1e8..c72d18a2a 100755
--- a/scripts/generate_code.py
+++ b/scripts/generate_code.py
@@ -470,6 +470,15 @@ flatc(
cwd=swift_code_gen
)
+# Swift Wasm Tests
+swift_Wasm_prefix = "swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests"
+flatc(
+ SWIFT_OPTS + BASE_OPTS,
+ schema="monster_test.fbs",
+ include="include_test",
+ prefix=swift_Wasm_prefix,
+)
+
# Nim Tests
NIM_OPTS = BASE_OPTS + ["--nim"]
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
diff --git a/src/idl_gen_swift.cpp b/src/idl_gen_swift.cpp
index f2ff5e960..d7d254567 100644
--- a/src/idl_gen_swift.cpp
+++ b/src/idl_gen_swift.cpp
@@ -483,12 +483,6 @@ class SwiftGenerator : public BaseGenerator {
"fileId: "
"{{STRUCTNAME}}.id, addPrefix: prefix) }";
}
- code_ +=
- "{{ACCESS_TYPE}} static func getRootAs{{SHORT_STRUCTNAME}}(bb: "
- "ByteBuffer) -> "
- "{{STRUCTNAME}} { return {{STRUCTNAME}}(Table(bb: bb, position: "
- "Int32(bb.read(def: UOffset.self, position: bb.reader)) + "
- "Int32(bb.reader))) }\n";
code_ += "private init(_ t: Table) { {{ACCESS}} = t }";
}
code_ +=
diff --git a/swift.swiftformat b/swift.swiftformat
index b198b9292..80e475a51 100644
--- a/swift.swiftformat
+++ b/swift.swiftformat
@@ -1,4 +1,4 @@
---swiftversion 5.1
+--swiftversion 5.7
# format
--indent 2
diff --git a/swift/Sources/FlatBuffers/ByteBuffer.swift b/swift/Sources/FlatBuffers/ByteBuffer.swift
index fead65efd..f5c681ac6 100644
--- a/swift/Sources/FlatBuffers/ByteBuffer.swift
+++ b/swift/Sources/FlatBuffers/ByteBuffer.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -429,13 +429,13 @@ public struct ByteBuffer {
}
/// Returns the written bytes into the ``ByteBuffer``
- public var underlyingBytes: [UInt8] {
- let cp = capacity &- writerIndex
- let start = memory.advanced(by: writerIndex)
- .bindMemory(to: UInt8.self, capacity: cp)
+ public var underlyingBytes: [UInt8] {
+ let cp = capacity &- writerIndex
+ let start = memory.advanced(by: writerIndex)
+ .bindMemory(to: UInt8.self, capacity: cp)
- let ptr = UnsafeBufferPointer(start: start, count: cp)
- return Array(ptr)
+ let ptr = UnsafeBufferPointer(start: start, count: cp)
+ return Array(ptr)
}
/// SkipPrefix Skips the first 4 bytes in case one of the following
diff --git a/swift/Sources/FlatBuffers/Constants.swift b/swift/Sources/FlatBuffers/Constants.swift
index 00614f1eb..d7436dd48 100644
--- a/swift/Sources/FlatBuffers/Constants.swift
+++ b/swift/Sources/FlatBuffers/Constants.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,11 @@
*/
#if !os(WASI)
- #if os(Linux)
- import CoreFoundation
- #else
- import Foundation
- #endif
+#if os(Linux)
+import CoreFoundation
+#else
+import Foundation
+#endif
#else
import SwiftOverlayShims
#endif
diff --git a/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_11.swift b/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_11.swift
index 3ed7ea242..07d2d8d2b 100644
--- a/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_11.swift
+++ b/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_11.swift
@@ -4,8 +4,8 @@ import Foundation
func run() {
// create a ByteBuffer(:) from an [UInt8] or Data()
let buf = [] // Get your data
-
+ var byteBuffer = ByteBuffer(bytes: buf)
// Get an accessor to the root object inside the buffer.
- let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
- // let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
+ let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
+ // let monster: Monster = getRoot(byteBuffer: &byteBuffer)
}
diff --git a/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_12.swift b/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_12.swift
index 895653ebf..0d9ff6943 100644
--- a/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_12.swift
+++ b/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_12.swift
@@ -4,10 +4,10 @@ import Foundation
func run() {
// create a ByteBuffer(:) from an [UInt8] or Data()
let buf = [] // Get your data
-
+ var byteBuffer = ByteBuffer(bytes: buf)
// Get an accessor to the root object inside the buffer.
- let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
- // let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
+ let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
+ // let monster: Monster = getRoot(byteBuffer: &byteBuffer)
let hp = monster.hp
let mana = monster.mana
diff --git a/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_13.swift b/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_13.swift
index 7aac982cf..1372d6fc0 100644
--- a/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_13.swift
+++ b/swift/Sources/FlatBuffers/Documentation.docc/Resources/code/swift/swift_code_13.swift
@@ -4,10 +4,10 @@ import Foundation
func run() {
// create a ByteBuffer(:) from an [UInt8] or Data()
let buf = [] // Get your data
-
+ var byteBuffer = ByteBuffer(bytes: buf)
// Get an accessor to the root object inside the buffer.
- let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
- // let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
+ let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
+ // let monster: Monster = getRoot(byteBuffer: &byteBuffer)
let hp = monster.hp
let mana = monster.mana
diff --git a/swift/Sources/FlatBuffers/Enum.swift b/swift/Sources/FlatBuffers/Enum.swift
index f0e99f399..ab5db06c9 100644
--- a/swift/Sources/FlatBuffers/Enum.swift
+++ b/swift/Sources/FlatBuffers/Enum.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift
index bfe36157f..f96ad6114 100644
--- a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift
+++ b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/FlatBufferObject.swift b/swift/Sources/FlatBuffers/FlatBufferObject.swift
index 520cb1d96..705c93463 100644
--- a/swift/Sources/FlatBuffers/FlatBufferObject.swift
+++ b/swift/Sources/FlatBuffers/FlatBufferObject.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/FlatBuffersUtils.swift b/swift/Sources/FlatBuffers/FlatBuffersUtils.swift
index 9941bd2d3..338988df7 100644
--- a/swift/Sources/FlatBuffers/FlatBuffersUtils.swift
+++ b/swift/Sources/FlatBuffers/FlatBuffersUtils.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/FlatbuffersErrors.swift b/swift/Sources/FlatBuffers/FlatbuffersErrors.swift
index 77e2f2b28..1a9284eba 100644
--- a/swift/Sources/FlatBuffers/FlatbuffersErrors.swift
+++ b/swift/Sources/FlatBuffers/FlatbuffersErrors.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,12 +66,12 @@ public enum FlatbuffersErrors: Error, Equatable {
#if !os(WASI)
extension FlatbuffersErrors {
- public static func == (
- lhs: FlatbuffersErrors,
- rhs: FlatbuffersErrors) -> Bool
- {
- lhs.localizedDescription == rhs.localizedDescription
- }
+ public static func == (
+ lhs: FlatbuffersErrors,
+ rhs: FlatbuffersErrors) -> Bool
+ {
+ lhs.localizedDescription == rhs.localizedDescription
+ }
}
#endif
diff --git a/swift/Sources/FlatBuffers/Int+extension.swift b/swift/Sources/FlatBuffers/Int+extension.swift
index f1c261e17..c8cd0e364 100644
--- a/swift/Sources/FlatBuffers/Int+extension.swift
+++ b/swift/Sources/FlatBuffers/Int+extension.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Message.swift b/swift/Sources/FlatBuffers/Message.swift
index e9739deec..172a339db 100644
--- a/swift/Sources/FlatBuffers/Message.swift
+++ b/swift/Sources/FlatBuffers/Message.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Mutable.swift b/swift/Sources/FlatBuffers/Mutable.swift
index 9763c3fd2..7a1a3d5bc 100644
--- a/swift/Sources/FlatBuffers/Mutable.swift
+++ b/swift/Sources/FlatBuffers/Mutable.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/NativeObject.swift b/swift/Sources/FlatBuffers/NativeObject.swift
index 582933851..9c72b50b7 100644
--- a/swift/Sources/FlatBuffers/NativeObject.swift
+++ b/swift/Sources/FlatBuffers/NativeObject.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Offset.swift b/swift/Sources/FlatBuffers/Offset.swift
index 5adb5728f..e433f35a2 100644
--- a/swift/Sources/FlatBuffers/Offset.swift
+++ b/swift/Sources/FlatBuffers/Offset.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Root.swift b/swift/Sources/FlatBuffers/Root.swift
index 0c593dcb4..6269148bb 100644
--- a/swift/Sources/FlatBuffers/Root.swift
+++ b/swift/Sources/FlatBuffers/Root.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/String+extension.swift b/swift/Sources/FlatBuffers/String+extension.swift
index cd92f7fd8..35c83cbdb 100644
--- a/swift/Sources/FlatBuffers/String+extension.swift
+++ b/swift/Sources/FlatBuffers/String+extension.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Struct.swift b/swift/Sources/FlatBuffers/Struct.swift
index 9996f4493..04cfba092 100644
--- a/swift/Sources/FlatBuffers/Struct.swift
+++ b/swift/Sources/FlatBuffers/Struct.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Table.swift b/swift/Sources/FlatBuffers/Table.swift
index 5c7822489..0da5919a8 100644
--- a/swift/Sources/FlatBuffers/Table.swift
+++ b/swift/Sources/FlatBuffers/Table.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/TableVerifier.swift b/swift/Sources/FlatBuffers/TableVerifier.swift
index 0338f0d32..45f0a5aba 100644
--- a/swift/Sources/FlatBuffers/TableVerifier.swift
+++ b/swift/Sources/FlatBuffers/TableVerifier.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/VeriferOptions.swift b/swift/Sources/FlatBuffers/VeriferOptions.swift
index bd88ba6b6..a760ffbab 100644
--- a/swift/Sources/FlatBuffers/VeriferOptions.swift
+++ b/swift/Sources/FlatBuffers/VeriferOptions.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Verifiable.swift b/swift/Sources/FlatBuffers/Verifiable.swift
index 7ecb45461..b445c4ce1 100644
--- a/swift/Sources/FlatBuffers/Verifiable.swift
+++ b/swift/Sources/FlatBuffers/Verifiable.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/swift/Sources/FlatBuffers/Verifier.swift b/swift/Sources/FlatBuffers/Verifier.swift
index 9ac397430..6daf6f50c 100644
--- a/swift/Sources/FlatBuffers/Verifier.swift
+++ b/swift/Sources/FlatBuffers/Verifier.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/tests/swift/Wasm.tests/.swift-version b/tests/swift/Wasm.tests/.swift-version
new file mode 100644
index 000000000..d9bd01e0a
--- /dev/null
+++ b/tests/swift/Wasm.tests/.swift-version
@@ -0,0 +1 @@
+wasm-5.7-SNAPSHOT-2022-09-24-a
\ No newline at end of file
diff --git a/tests/swift/Wasm.tests/Package.swift b/tests/swift/Wasm.tests/Package.swift
index bd32307ef..e45db6ffd 100644
--- a/tests/swift/Wasm.tests/Package.swift
+++ b/tests/swift/Wasm.tests/Package.swift
@@ -30,5 +30,5 @@ let package = Package(
name: "Wasm"),
.testTarget(
name: "FlatBuffers.Test.Swift.WasmTests",
- dependencies: ["FlatBuffers"])
+ dependencies: ["FlatBuffers"]),
])
diff --git a/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift b/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift
index c14abeb4f..1b0952bc0 100644
--- a/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift
+++ b/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift
@@ -1 +1,17 @@
+/*
+ * Copyright 2023 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
public struct Wasm {}
\ No newline at end of file
diff --git a/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift b/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift
index 614791e0a..adc918a5d 100644
--- a/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift
+++ b/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
// swiftformat:disable all
XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
// swiftformat:enable all
- let monster = MyGame_Example_Monster.getRootAsMonster(bb: bytes.buffer)
+ var buffer = bytes.buffer
+ let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
readMonster(monster: monster)
mutateMonster(fb: bytes.buffer)
readMonster(monster: monster)
@@ -69,7 +70,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
Monster.add(name: name, &fbb)
let root = Monster.endMonster(&fbb, start: mStart)
fbb.finish(offset: root)
- let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
+ var buffer = fbb.sizedBuffer
+ let newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
XCTAssertNil(newMonster.pos)
XCTAssertEqual(newMonster.name, "Frodo")
}
@@ -91,7 +93,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let root = Monster.endMonster(&fbb, start: mStart)
fbb.finish(offset: root)
- let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
+ var buffer = fbb.sizedBuffer
+ let newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
XCTAssertEqual(newMonster.pos!.x, 10)
XCTAssertEqual(newMonster.name, "Barney")
}
@@ -106,7 +109,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
nameOffset: name,
testarrayofboolsVectorOffset: bools)
fbb.finish(offset: root)
- let monster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
+ var buffer = fbb.sizedBuffer
+ let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
let values = monster.testarrayofbools
@@ -130,9 +134,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
readFlatbufferMonster(monster: &monster)
let unpacked: MyGame_Example_MonsterT? = monster.unpack()
readObjectApi(monster: unpacked!)
- guard let buffer = unpacked?.serialize()
+ guard var buffer = unpacked?.serialize()
else { fatalError("Couldnt generate bytebuffer") }
- var newMonster = Monster.getRootAsMonster(bb: buffer)
+ var newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
readFlatbufferMonster(monster: &newMonster)
}
@@ -198,7 +202,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
}
func mutateMonster(fb: ByteBuffer) {
- let monster = Monster.getRootAsMonster(bb: fb)
+ var fb = fb
+
+ let monster: Monster = getRoot(byteBuffer: &fb)
XCTAssertFalse(monster.mutate(mana: 10))
XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney")
XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo")
diff --git a/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/monster_test_generated.swift b/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/monster_test_generated.swift
index d23df8786..974c5d48b 100644
--- a/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/monster_test_generated.swift
+++ b/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/monster_test_generated.swift
@@ -685,8 +685,6 @@ public struct MyGame_InParentNamespace: FlatBufferObject, Verifiable, ObjectAPIP
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_InParentNamespace.id, addPrefix: prefix) }
- public static func getRootAsInParentNamespace(bb: ByteBuffer) -> MyGame_InParentNamespace { return MyGame_InParentNamespace(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -739,8 +737,6 @@ public struct MyGame_Example2_Monster: FlatBufferObject, Verifiable, ObjectAPIPa
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example2_Monster.id, addPrefix: prefix) }
- public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example2_Monster { return MyGame_Example2_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -793,8 +789,6 @@ internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferObject, Verifi
internal static var id: String { "MONS" }
internal static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TestSimpleTableWithEnum.id, addPrefix: prefix) }
- internal static func getRootAsTestSimpleTableWithEnum(bb: ByteBuffer) -> MyGame_Example_TestSimpleTableWithEnum { return MyGame_Example_TestSimpleTableWithEnum(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -876,8 +870,6 @@ public struct MyGame_Example_Stat: FlatBufferObject, Verifiable, ObjectAPIPacker
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Stat.id, addPrefix: prefix) }
- public static func getRootAsStat(bb: ByteBuffer) -> MyGame_Example_Stat { return MyGame_Example_Stat(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -1017,8 +1009,6 @@ public struct MyGame_Example_Referrable: FlatBufferObject, Verifiable, ObjectAPI
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Referrable.id, addPrefix: prefix) }
- public static func getRootAsReferrable(bb: ByteBuffer) -> MyGame_Example_Referrable { return MyGame_Example_Referrable(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -1125,8 +1115,6 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Monster.id, addPrefix: prefix) }
- public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example_Monster { return MyGame_Example_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -1344,19 +1332,19 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
@discardableResult public func mutate(longEnumNormalDefault: MyGame_Example_LongEnum) -> Bool {let o = _accessor.offset(VTOFFSET.longEnumNormalDefault.v); return _accessor.mutate(longEnumNormalDefault.rawValue, index: o) }
public var nanDefault: Float32 { let o = _accessor.offset(VTOFFSET.nanDefault.v); return o == 0 ? .nan : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(nanDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.nanDefault.v); return _accessor.mutate(nanDefault, index: o) }
- public var infDefault: Float32 { let o = _accessor.offset(VTOFFSET.infDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
+ public var infDefault: Float32 { let o = _accessor.offset(VTOFFSET.infDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(infDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.infDefault.v); return _accessor.mutate(infDefault, index: o) }
- public var positiveInfDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
+ public var positiveInfDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(positiveInfDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.positiveInfDefault.v); return _accessor.mutate(positiveInfDefault, index: o) }
- public var infinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.infinityDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
+ public var infinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.infinityDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(infinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.infinityDefault.v); return _accessor.mutate(infinityDefault, index: o) }
- public var positiveInfinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfinityDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
+ public var positiveInfinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfinityDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(positiveInfinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.positiveInfinityDefault.v); return _accessor.mutate(positiveInfinityDefault, index: o) }
public var negativeInfDefault: Float32 { let o = _accessor.offset(VTOFFSET.negativeInfDefault.v); return o == 0 ? -.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(negativeInfDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.negativeInfDefault.v); return _accessor.mutate(negativeInfDefault, index: o) }
public var negativeInfinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.negativeInfinityDefault.v); return o == 0 ? -.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(negativeInfinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.negativeInfinityDefault.v); return _accessor.mutate(negativeInfinityDefault, index: o) }
- public var doubleInfDefault: Double { let o = _accessor.offset(VTOFFSET.doubleInfDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Double.self, at: o) }
+ public var doubleInfDefault: Double { let o = _accessor.offset(VTOFFSET.doubleInfDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Double.self, at: o) }
@discardableResult public func mutate(doubleInfDefault: Double) -> Bool {let o = _accessor.offset(VTOFFSET.doubleInfDefault.v); return _accessor.mutate(doubleInfDefault, index: o) }
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 62) }
public static func add(pos: MyGame_Example_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
@@ -1423,13 +1411,13 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
public static func add(longEnumNonEnumDefault: MyGame_Example_LongEnum, _ fbb: inout FlatBufferBuilder) { fbb.add(element: longEnumNonEnumDefault.rawValue, def: 0, at: VTOFFSET.longEnumNonEnumDefault.p) }
public static func add(longEnumNormalDefault: MyGame_Example_LongEnum, _ fbb: inout FlatBufferBuilder) { fbb.add(element: longEnumNormalDefault.rawValue, def: 2, at: VTOFFSET.longEnumNormalDefault.p) }
public static func add(nanDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: nanDefault, def: .nan, at: VTOFFSET.nanDefault.p) }
- public static func add(infDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infDefault, def: +.infinity, at: VTOFFSET.infDefault.p) }
- public static func add(positiveInfDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfDefault, def: +.infinity, at: VTOFFSET.positiveInfDefault.p) }
- public static func add(infinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infinityDefault, def: +.infinity, at: VTOFFSET.infinityDefault.p) }
- public static func add(positiveInfinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfinityDefault, def: +.infinity, at: VTOFFSET.positiveInfinityDefault.p) }
+ public static func add(infDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infDefault, def: .infinity, at: VTOFFSET.infDefault.p) }
+ public static func add(positiveInfDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfDefault, def: .infinity, at: VTOFFSET.positiveInfDefault.p) }
+ public static func add(infinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infinityDefault, def: .infinity, at: VTOFFSET.infinityDefault.p) }
+ public static func add(positiveInfinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfinityDefault, def: .infinity, at: VTOFFSET.positiveInfinityDefault.p) }
public static func add(negativeInfDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: negativeInfDefault, def: -.infinity, at: VTOFFSET.negativeInfDefault.p) }
public static func add(negativeInfinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: negativeInfinityDefault, def: -.infinity, at: VTOFFSET.negativeInfinityDefault.p) }
- public static func add(doubleInfDefault: Double, _ fbb: inout FlatBufferBuilder) { fbb.add(element: doubleInfDefault, def: +.infinity, at: VTOFFSET.doubleInfDefault.p) }
+ public static func add(doubleInfDefault: Double, _ fbb: inout FlatBufferBuilder) { fbb.add(element: doubleInfDefault, def: .infinity, at: VTOFFSET.doubleInfDefault.p) }
public static func endMonster(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); fbb.require(table: end, fields: [10]); return end }
public static func createMonster(
_ fbb: inout FlatBufferBuilder,
@@ -1487,13 +1475,13 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
longEnumNonEnumDefault: MyGame_Example_LongEnum = .longone,
longEnumNormalDefault: MyGame_Example_LongEnum = .longone,
nanDefault: Float32 = .nan,
- infDefault: Float32 = +.infinity,
- positiveInfDefault: Float32 = +.infinity,
- infinityDefault: Float32 = +.infinity,
- positiveInfinityDefault: Float32 = +.infinity,
+ infDefault: Float32 = .infinity,
+ positiveInfDefault: Float32 = .infinity,
+ infinityDefault: Float32 = .infinity,
+ positiveInfinityDefault: Float32 = .infinity,
negativeInfDefault: Float32 = -.infinity,
negativeInfinityDefault: Float32 = -.infinity,
- doubleInfDefault: Double = +.infinity
+ doubleInfDefault: Double = .infinity
) -> Offset {
let __start = MyGame_Example_Monster.startMonster(&fbb)
MyGame_Example_Monster.add(pos: pos, &fbb)
@@ -2108,16 +2096,16 @@ extension MyGame_Example_Monster: Encodable {
if !nanDefault.isNaN {
try container.encodeIfPresent(nanDefault, forKey: .nanDefault)
}
- if infDefault != +.infinity {
+ if infDefault != .infinity {
try container.encodeIfPresent(infDefault, forKey: .infDefault)
}
- if positiveInfDefault != +.infinity {
+ if positiveInfDefault != .infinity {
try container.encodeIfPresent(positiveInfDefault, forKey: .positiveInfDefault)
}
- if infinityDefault != +.infinity {
+ if infinityDefault != .infinity {
try container.encodeIfPresent(infinityDefault, forKey: .infinityDefault)
}
- if positiveInfinityDefault != +.infinity {
+ if positiveInfinityDefault != .infinity {
try container.encodeIfPresent(positiveInfinityDefault, forKey: .positiveInfinityDefault)
}
if negativeInfDefault != -.infinity {
@@ -2126,7 +2114,7 @@ extension MyGame_Example_Monster: Encodable {
if negativeInfinityDefault != -.infinity {
try container.encodeIfPresent(negativeInfinityDefault, forKey: .negativeInfinityDefault)
}
- if doubleInfDefault != +.infinity {
+ if doubleInfDefault != .infinity {
try container.encodeIfPresent(doubleInfDefault, forKey: .doubleInfDefault)
}
}
@@ -2403,13 +2391,13 @@ public class MyGame_Example_MonsterT: NativeObject {
longEnumNonEnumDefault = .longone
longEnumNormalDefault = .longone
nanDefault = .nan
- infDefault = +.infinity
- positiveInfDefault = +.infinity
- infinityDefault = +.infinity
- positiveInfinityDefault = +.infinity
+ infDefault = .infinity
+ positiveInfDefault = .infinity
+ infinityDefault = .infinity
+ positiveInfinityDefault = .infinity
negativeInfDefault = -.infinity
negativeInfinityDefault = -.infinity
- doubleInfDefault = +.infinity
+ doubleInfDefault = .infinity
}
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_Monster.self) }
@@ -2423,8 +2411,6 @@ public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAP
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TypeAliases.id, addPrefix: prefix) }
- public static func getRootAsTypeAliases(bb: ByteBuffer) -> MyGame_Example_TypeAliases { return MyGame_Example_TypeAliases(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/benchmarks/Sources/benchmarks/main.swift b/tests/swift/benchmarks/Sources/benchmarks/main.swift
index a25a646e0..e41d5ce57 100644
--- a/tests/swift/benchmarks/Sources/benchmarks/main.swift
+++ b/tests/swift/benchmarks/Sources/benchmarks/main.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/tests/swift/tests/CodeGenerationTests/test_import_generated.swift b/tests/swift/tests/CodeGenerationTests/test_import_generated.swift
index c0af7d297..aaeb0c042 100644
--- a/tests/swift/tests/CodeGenerationTests/test_import_generated.swift
+++ b/tests/swift/tests/CodeGenerationTests/test_import_generated.swift
@@ -10,8 +10,6 @@ internal struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker {
internal var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- internal static func getRootAsMessage(bb: ByteBuffer) -> Message { return Message(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/CodeGenerationTests/test_no_include_generated.swift b/tests/swift/tests/CodeGenerationTests/test_no_include_generated.swift
index 143496607..608424fa9 100644
--- a/tests/swift/tests/CodeGenerationTests/test_no_include_generated.swift
+++ b/tests/swift/tests/CodeGenerationTests/test_no_include_generated.swift
@@ -76,8 +76,6 @@ public struct InternalMessage: FlatBufferObject, Verifiable, ObjectAPIPacker {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsInternalMessage(bb: ByteBuffer) -> InternalMessage { return InternalMessage(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -161,8 +159,6 @@ public struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsMessage(bb: ByteBuffer) -> Message { return Message(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift b/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift
index 86e422c67..cfd3009e5 100644
--- a/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift
+++ b/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift
index 9f02d8d94..1fec4becf 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
// swiftformat:disable all
XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
// swiftformat:enable all
- let monster = MyGame_Example_Monster.getRootAsMonster(bb: bytes.buffer)
+ var buffer = bytes.buffer
+ let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
readMonster(monster: monster)
mutateMonster(fb: bytes.buffer)
readMonster(monster: monster)
@@ -78,7 +79,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
Monster.add(name: name, &fbb)
let root = Monster.endMonster(&fbb, start: mStart)
fbb.finish(offset: root)
- let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
+ var buffer = fbb.sizedBuffer
+ let newMonster: Monster = getRoot(byteBuffer: &buffer)
XCTAssertNil(newMonster.pos)
XCTAssertEqual(newMonster.name, "Frodo")
}
@@ -100,7 +102,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let root = Monster.endMonster(&fbb, start: mStart)
fbb.finish(offset: root)
- let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
+ var buffer = fbb.sizedBuffer
+ let newMonster: Monster = getRoot(byteBuffer: &buffer)
XCTAssertEqual(newMonster.pos!.x, 10)
XCTAssertEqual(newMonster.name, "Barney")
}
@@ -110,11 +113,11 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
var array: [UInt8] = [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]
// swiftformat:enable all
let unpacked = array
- .withUnsafeMutableBytes { (memory) -> MyGame_Example_MonsterT in
- let bytes = ByteBuffer(
+ .withUnsafeMutableBytes { memory -> MyGame_Example_MonsterT in
+ var bytes = ByteBuffer(
assumingMemoryBound: memory.baseAddress!,
capacity: memory.count)
- var monster = Monster.getRootAsMonster(bb: bytes)
+ var monster: Monster = getRoot(byteBuffer: &bytes)
readFlatbufferMonster(monster: &monster)
let unpacked = monster.unpack()
return unpacked
@@ -132,8 +135,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
nameOffset: name,
testarrayofboolsVectorOffset: bools)
fbb.finish(offset: root)
- let monster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
-
+ var buffer = fbb.sizedBuffer
+ let monster: Monster = getRoot(byteBuffer: &buffer)
let values = monster.testarrayofbools
XCTAssertEqual(boolArray, values)
@@ -156,9 +159,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
readFlatbufferMonster(monster: &monster)
let unpacked: MyGame_Example_MonsterT? = monster.unpack()
readObjectApi(monster: unpacked!)
- guard let buffer = unpacked?.serialize()
+ guard var buffer = unpacked?.serialize()
else { fatalError("Couldnt generate bytebuffer") }
- var newMonster = Monster.getRootAsMonster(bb: buffer)
+ var newMonster: Monster = getRoot(byteBuffer: &buffer)
readFlatbufferMonster(monster: &newMonster)
}
@@ -224,7 +227,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
}
func mutateMonster(fb: ByteBuffer) {
- let monster = Monster.getRootAsMonster(bb: fb)
+ var fb = fb
+ let monster: Monster = getRoot(byteBuffer: &fb)
XCTAssertFalse(monster.mutate(mana: 10))
XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney")
XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo")
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift
index e6ee5a5ab..30d16b199 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,50 +19,54 @@ import XCTest
final class FlatBuffersNanInfTests: XCTestCase {
- func createTestTable() -> FlatBufferBuilder {
- var fbb = FlatBufferBuilder()
- let msg = Swift_Tests_NanInfTable.createNanInfTable(&fbb,
- valueNan: .nan,
- valueInf: .infinity,
- valueNinf: -.infinity,
- value: 100.0
- )
- fbb.finish(offset: msg)
- return fbb
- }
+ func createTestTable() -> FlatBufferBuilder {
+ var fbb = FlatBufferBuilder()
+ let msg = Swift_Tests_NanInfTable.createNanInfTable(
+ &fbb,
+ valueNan: .nan,
+ valueInf: .infinity,
+ valueNinf: -.infinity,
+ value: 100.0)
+ fbb.finish(offset: msg)
+ return fbb
+ }
- func testInfNanBinary() {
- let fbb = createTestTable()
- let data = fbb.sizedByteArray
-
- let table = Swift_Tests_NanInfTable.getRootAsNanInfTable(bb: ByteBuffer(bytes: data))
- XCTAssert(table.defaultNan.isNaN)
- XCTAssertEqual(table.defaultInf, .infinity)
- XCTAssertEqual(table.defaultNinf, -.infinity)
- XCTAssert(table.valueNan.isNaN)
- XCTAssertEqual(table.valueInf, .infinity)
- XCTAssertEqual(table.valueNinf, -.infinity)
- XCTAssertEqual(table.value, 100.0)
+ func testInfNanBinary() {
+ let fbb = createTestTable()
+ let data = fbb.sizedByteArray
+
+ var buffer = ByteBuffer(bytes: data)
+ let table: Swift_Tests_NanInfTable = getRoot(byteBuffer: &buffer)
+ XCTAssert(table.defaultNan.isNaN)
+ XCTAssertEqual(table.defaultInf, .infinity)
+ XCTAssertEqual(table.defaultNinf, -.infinity)
+ XCTAssert(table.valueNan.isNaN)
+ XCTAssertEqual(table.valueInf, .infinity)
+ XCTAssertEqual(table.valueNinf, -.infinity)
+ XCTAssertEqual(table.value, 100.0)
+ }
+
+ func testInfNanJSON() {
+ let fbb = createTestTable()
+ var bb = fbb.sizedBuffer
+ do {
+ let reader: Swift_Tests_NanInfTable = try getCheckedRoot(byteBuffer: &bb)
+ let encoder = JSONEncoder()
+ encoder.keyEncodingStrategy = .convertToSnakeCase
+ encoder.nonConformingFloatEncodingStrategy =
+ .convertToString(
+ positiveInfinity: "inf",
+ negativeInfinity: "-inf",
+ nan: "nan")
+ let data = try encoder.encode(reader)
+ XCTAssertEqual(data, jsonData.data(using: .utf8))
+ } catch {
+ XCTFail(error.localizedDescription)
}
-
- func testInfNanJSON() {
- let fbb = createTestTable()
- var bb = fbb.sizedBuffer
- do {
- let reader: Swift_Tests_NanInfTable = try getCheckedRoot(byteBuffer: &bb)
- let encoder = JSONEncoder()
- encoder.keyEncodingStrategy = .convertToSnakeCase
- encoder.nonConformingFloatEncodingStrategy =
- .convertToString(positiveInfinity: "inf", negativeInfinity: "-inf", nan: "nan")
- let data = try encoder.encode(reader)
- XCTAssertEqual(data, jsonData.data(using: .utf8))
- } catch {
- XCTFail(error.localizedDescription)
- }
- }
-
- var jsonData: String {
- "{\"value_inf\":\"inf\",\"value\":100,\"value_nan\":\"nan\",\"value_ninf\":\"-inf\"}"
- }
-
+ }
+
+ var jsonData: String {
+ "{\"value_inf\":\"inf\",\"value\":100,\"value_nan\":\"nan\",\"value_ninf\":\"-inf\"}"
+ }
+
}
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift
index 203258978..21b4d4b5e 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@ final class FlatBuffersStructsTests: XCTestCase {
let root = TestMutatingBool.endTestMutatingBool(&fbb, start: start)
fbb.finish(offset: root)
- let testMutatingBool = TestMutatingBool
- .getRootAsTestMutatingBool(bb: fbb.sizedBuffer)
+ var buffer = fbb.sizedBuffer
+ let testMutatingBool: TestMutatingBool = getRoot(byteBuffer: &buffer)
let property = testMutatingBool.mutableB
XCTAssertEqual(property?.property, false)
property?.mutate(property: false)
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift
index 379e73318..5f4916847 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -108,8 +108,8 @@ final class FlatBuffersTests: XCTestCase {
justEnum: .one,
maybeEnum: nil)
b.finish(offset: root)
- let scalarTable = optional_scalars_ScalarStuff
- .getRootAsScalarStuff(bb: b.sizedBuffer)
+ var buffer = b.sizedBuffer
+ let scalarTable: optional_scalars_ScalarStuff = getRoot(byteBuffer: &buffer)
XCTAssertEqual(scalarTable.justI8, 80)
XCTAssertNil(scalarTable.maybeI8)
XCTAssertEqual(scalarTable.maybeBool, true)
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift
index eb8a10c5c..ee6110257 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -122,7 +122,8 @@ final class FlatBuffersUnionTests: XCTestCase {
charactersVectorOffset: characterVector)
Movie.finish(&fb, end: end)
- var movie = Movie.getRootAsMovie(bb: fb.buffer)
+ var buffer = fb.buffer
+ var movie: Movie = getRoot(byteBuffer: &buffer)
XCTAssertEqual(movie.charactersTypeCount, Int32(characterType.count))
XCTAssertEqual(movie.charactersCount, Int32(characters.count))
@@ -151,7 +152,8 @@ final class FlatBuffersUnionTests: XCTestCase {
let newMovie = Movie.pack(&fb, obj: &objc)
fb.finish(offset: newMovie)
- let packedMovie = Movie.getRootAsMovie(bb: fb.buffer)
+ var _buffer = fb.buffer
+ let packedMovie: Movie = getRoot(byteBuffer: &_buffer)
XCTAssertEqual(
packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
@@ -185,7 +187,8 @@ final class FlatBuffersUnionTests: XCTestCase {
charactersVectorOffset: characterVector)
Movie.finish(&fb, end: end)
- var movie = Movie.getRootAsMovie(bb: fb.sizedBuffer)
+ var buffer = fb.sizedBuffer
+ var movie: Movie = getRoot(byteBuffer: &buffer)
XCTAssertEqual(movie.mainCharacter(type: String.self), string)
XCTAssertEqual(
movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
@@ -200,7 +203,8 @@ final class FlatBuffersUnionTests: XCTestCase {
let newMovie = Movie.pack(&fb, obj: &objc)
fb.finish(offset: newMovie)
- let packedMovie = Movie.getRootAsMovie(bb: fb.buffer)
+ var _buffer = fb.buffer
+ let packedMovie: Movie = getRoot(byteBuffer: &_buffer)
XCTAssertEqual(packedMovie.mainCharacter(type: String.self), string)
XCTAssertEqual(
packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift
index 122facb35..61dbe50ab 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -118,7 +118,8 @@ final class FlatBuffersVectors: XCTestCase {
let finish = Swift_Tests_Vectors.endVectors(&builder, start: start)
builder.finish(offset: finish)
- let msg = Swift_Tests_Vectors.getRootAsVectors(bb: ByteBuffer(bytes: builder.sizedByteArray))
+ var byteBuffer = ByteBuffer(bytes: builder.sizedByteArray)
+ let msg: Swift_Tests_Vectors = getRoot(byteBuffer: &byteBuffer)
XCTAssertEqual(msg.hasNone, false)
XCTAssertEqual(msg.hasEmpty, true)
XCTAssertEqual(msg.emptyCount, 0)
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift
index a6e1cb09b..f85abf63d 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift
index cd97f25a2..39e13b115 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,8 @@ class FlatBuffersMoreDefaults: XCTestCase {
var fbb = FlatBufferBuilder()
let root = MoreDefaults.createMoreDefaults(&fbb)
fbb.finish(offset: root)
- let defaults = MoreDefaults.getRootAsMoreDefaults(bb: fbb.sizedBuffer)
+ var byteBuffer = fbb.sizedBuffer
+ let defaults: MoreDefaults = getRoot(byteBuffer: &byteBuffer)
XCTAssertEqual(defaults.emptyString, "")
XCTAssertEqual(defaults.someString, "some")
XCTAssertEqual(defaults.ints, [])
@@ -46,8 +47,8 @@ class FlatBuffersMoreDefaults: XCTestCase {
XCTAssertEqual(defaults.abcs, [])
XCTAssertEqual(defaults.bools, [])
- let buffer = defaults.serialize(builder: &fbb, type: MoreDefaults.self)
- let fDefaults = MoreDefaults.getRootAsMoreDefaults(bb: buffer)
+ var buffer = defaults.serialize(builder: &fbb, type: MoreDefaults.self)
+ let fDefaults: MoreDefaults = getRoot(byteBuffer: &buffer)
XCTAssertEqual(fDefaults.emptyString, "")
XCTAssertEqual(fDefaults.someString, "some")
XCTAssertEqual(fDefaults.ints, [])
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift
index cb26c27d4..d7f949b18 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -205,7 +205,9 @@ final class FlatbuffersVerifierTests: XCTestCase {
// swiftformat:disable all
var byteBuffer = ByteBuffer(bytes: [20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
// swiftformat:enable all
- XCTAssertThrowsError(try getCheckedRoot(byteBuffer: &byteBuffer, fileId: "FLEX") as Movie)
+ XCTAssertThrowsError(try getCheckedRoot(
+ byteBuffer: &byteBuffer,
+ fileId: "FLEX") as Movie)
}
func testVerifyPrefixedBuffer() {
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/MutatingBool_generated.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/MutatingBool_generated.swift
index 446a8add2..0b4f39e48 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/MutatingBool_generated.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/MutatingBool_generated.swift
@@ -78,8 +78,6 @@ public struct TestMutatingBool: FlatBufferObject, Verifiable, ObjectAPIPacker {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsTestMutatingBool(bb: ByteBuffer) -> TestMutatingBool { return TestMutatingBool(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift
index e15ea83c9..e164fc3be 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/monster_test_generated.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/monster_test_generated.swift
index bde189f46..974c5d48b 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/monster_test_generated.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/monster_test_generated.swift
@@ -685,8 +685,6 @@ public struct MyGame_InParentNamespace: FlatBufferObject, Verifiable, ObjectAPIP
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_InParentNamespace.id, addPrefix: prefix) }
- public static func getRootAsInParentNamespace(bb: ByteBuffer) -> MyGame_InParentNamespace { return MyGame_InParentNamespace(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -739,8 +737,6 @@ public struct MyGame_Example2_Monster: FlatBufferObject, Verifiable, ObjectAPIPa
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example2_Monster.id, addPrefix: prefix) }
- public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example2_Monster { return MyGame_Example2_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -793,8 +789,6 @@ internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferObject, Verifi
internal static var id: String { "MONS" }
internal static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TestSimpleTableWithEnum.id, addPrefix: prefix) }
- internal static func getRootAsTestSimpleTableWithEnum(bb: ByteBuffer) -> MyGame_Example_TestSimpleTableWithEnum { return MyGame_Example_TestSimpleTableWithEnum(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -876,8 +870,6 @@ public struct MyGame_Example_Stat: FlatBufferObject, Verifiable, ObjectAPIPacker
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Stat.id, addPrefix: prefix) }
- public static func getRootAsStat(bb: ByteBuffer) -> MyGame_Example_Stat { return MyGame_Example_Stat(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -1017,8 +1009,6 @@ public struct MyGame_Example_Referrable: FlatBufferObject, Verifiable, ObjectAPI
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Referrable.id, addPrefix: prefix) }
- public static func getRootAsReferrable(bb: ByteBuffer) -> MyGame_Example_Referrable { return MyGame_Example_Referrable(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -1125,8 +1115,6 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Monster.id, addPrefix: prefix) }
- public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example_Monster { return MyGame_Example_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -2423,8 +2411,6 @@ public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAP
public static var id: String { "MONS" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TypeAliases.id, addPrefix: prefix) }
- public static func getRootAsTypeAliases(bb: ByteBuffer) -> MyGame_Example_TypeAliases { return MyGame_Example_TypeAliases(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/more_defaults_generated.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/more_defaults_generated.swift
index c9edf77e4..d18f40911 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/more_defaults_generated.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/more_defaults_generated.swift
@@ -33,8 +33,6 @@ public struct MoreDefaults: FlatBufferObject, Verifiable, ObjectAPIPacker {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsMoreDefaults(bb: ByteBuffer) -> MoreDefaults { return MoreDefaults(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/nan_inf_test_generated.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/nan_inf_test_generated.swift
index ef2cae560..1c2faac4d 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/nan_inf_test_generated.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/nan_inf_test_generated.swift
@@ -10,8 +10,6 @@ public struct Swift_Tests_NanInfTable: FlatBufferObject, Verifiable {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsNanInfTable(bb: ByteBuffer) -> Swift_Tests_NanInfTable { return Swift_Tests_NanInfTable(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/optional_scalars_generated.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/optional_scalars_generated.swift
index 099fe6627..dfbfa9d4a 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/optional_scalars_generated.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/optional_scalars_generated.swift
@@ -35,8 +35,6 @@ public struct optional_scalars_ScalarStuff: FlatBufferObject, Verifiable {
public static var id: String { "NULL" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: optional_scalars_ScalarStuff.id, addPrefix: prefix) }
- public static func getRootAsScalarStuff(bb: ByteBuffer) -> optional_scalars_ScalarStuff { return optional_scalars_ScalarStuff(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/union_vector_generated.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/union_vector_generated.swift
index 40db53faf..b80cc12dc 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/union_vector_generated.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/union_vector_generated.swift
@@ -330,8 +330,6 @@ public struct Attacker: FlatBufferObject, Verifiable, ObjectAPIPacker {
public static var id: String { "MOVI" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Attacker.id, addPrefix: prefix) }
- public static func getRootAsAttacker(bb: ByteBuffer) -> Attacker { return Attacker(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -413,8 +411,6 @@ public struct HandFan: FlatBufferObject, Verifiable, ObjectAPIPacker {
public static var id: String { "MOVI" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: HandFan.id, addPrefix: prefix) }
- public static func getRootAsHandFan(bb: ByteBuffer) -> HandFan { return HandFan(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
@@ -496,8 +492,6 @@ public struct Movie: FlatBufferObject, Verifiable, ObjectAPIPacker {
public static var id: String { "MOVI" }
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Movie.id, addPrefix: prefix) }
- public static func getRootAsMovie(bb: ByteBuffer) -> Movie { return Movie(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/vector_has_test_generated.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/vector_has_test_generated.swift
index c4a0b4368..0e07c65a1 100644
--- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/vector_has_test_generated.swift
+++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/vector_has_test_generated.swift
@@ -10,8 +10,6 @@ public struct Swift_Tests_Vectors: FlatBufferObject, Verifiable {
public var __buffer: ByteBuffer! { return _accessor.bb }
private var _accessor: Table
- public static func getRootAsVectors(bb: ByteBuffer) -> Swift_Tests_Vectors { return Swift_Tests_Vectors(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
-
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
diff --git a/tests/swift/tests/Tests/LinuxMain.swift b/tests/swift/tests/Tests/LinuxMain.swift
index d909d0793..a959fc769 100644
--- a/tests/swift/tests/Tests/LinuxMain.swift
+++ b/tests/swift/tests/Tests/LinuxMain.swift
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Google Inc. All rights reserved.
+ * Copyright 2023 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.