title: Swift Object Serialization sidebar_position: 0 id: index license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You 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
Apache Fory Swift provides high-performance object graph serialization with strong type safety, macro-based code generation, schema evolution, and cross-language compatibility.
@ForyStruct, @ForyEnum, and @ForyUnion macros for zero-boilerplate model serializationAdd 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") ] ) ]
import Fory @ForyStruct struct User: Equatable { var name: String = "" var age: Int32 = 0 } let fory = Fory() try 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)
Before decoding bytes from outside the application trust boundary, read Swift Security.