Swift Setup
Fory Swift provides xlang Object Serialization and compiler-generated models. It is distributed through Swift Package Manager, uses Swift tools 6.0, and targets macOS 13 or later and iOS 16 or later.
Verify the Toolchain
swift --version
Object Serialization
Create an executable package:
swift package init --type executable --name ForyExample
Add the released package and depend on its Fory library in the generated Package.swift:
Package.swift
dependencies: [
.package(url: "https://github.com/apache/fory.git", exact: "1.5.0")
],
targets: [
.executableTarget(
name: "ForyExample",
dependencies: [.product(name: "Fory", package: "fory")]
)
]
Replace Sources/main.swift with:
Sources/main.swift
import Fory
@ForyStruct
struct User: Equatable {
var id: Int64 = 0
var name: String = ""
}
let fory = Fory()
try fory.register(User.self, id: 1)
let input = User(id: 1, name: "Alice")
let bytes = try fory.serialize(input)
let decoded: User = try fory.deserialize(bytes)
assert(input == decoded)
swift run
Swift uses xlang mode. Continue with Swift Object Serialization, xlang types, configuration, and schema evolution.
Other Capabilities
- Fory IDL and Compiler generates Swift models and registration helpers. See Compiler Getting Started and the Swift generated-code guide.