Skip to main content
Version: dev

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
  • @ForyObject macro 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

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)