Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Swift

Generates Swift structs with Codable protocol.

Type Mappings

Rust TypeSwift Type
StringString
boolBool
u8, u16, u32, u64UInt8, UInt16, UInt32, UInt64
i8, i16, i32, i64Int8, Int16, Int32, Int64
f32, f64Float, Double
UuidUUID
DateTime<Utc>Date
Option<T>T?
Vec<T>[T]
HashMap<K, V>[K: V]

Example

Rust:

#![allow(unused)]
fn main() {
#[derive(TypeWriter)]
#[sync_to(swift)]
pub struct User {
    pub id: String,
    pub email: String,
    pub age: Option<u32>,
}
}

Generated:

struct User: Codable {
    let id: String
    let email: String
    let age: UInt32?
}

File Naming

Files use PascalCase by default: UserProfileUserProfile.swift

[swift]
file_style = "snake_case"  # user_profile.swift