Swift Serialization Guide
Apache Fory Swift provides high-performance object graph serialization with strong type safety, macro-based code generation, schema evolution, and cross-language compatibility.
Why Fory Swift?
- Fast binary serialization for Swift value and reference types
@ForyObjectmacro for zero-boilerplate model serialization- Cross-language protocol compatibility (
xlang) with Java, Rust, Go, Python, and more - Compatible mode for schema evolution across versions
- Built-in support for dynamic values (
Any,AnyObject,any Serializer,AnyHashable) - Reference tracking for shared/circular graphs, including weak references on classes
Install
Add Fory Swift from the Apache Fory GitHub repository:
dependencies: [
.package(url: "https://github.com/apache/fory.git", exact: "$version")
],
targets: [
.target(
name: "MyApp",
dependencies: [
.product(name: "Fory", package: "fory")
]
)
]
Guide Contents
- Configuration
- Basic Serialization
- Type Registration
- Custom Serializers
- Field Configuration
- Shared and Circular References
- Polymorphism and Dynamic Types
- Schema Evolution
- Cross-Language Serialization
- Row Format Status
- Troubleshooting
Quick Example
import Fory
@ForyObject
struct User: Equatable {
var name: String = ""
var age: Int32 = 0
}
let fory = Fory()
fory.register(User.self, id: 1)
let input = User(name: "alice", age: 30)
let data = try fory.serialize(input)
let output: User = try fory.deserialize(data)
assert(input == output)