SwiftConf 2026 in Cologne, Germany gathers iOS, macOS, and server-side Swift developers. UUID v7 sessions address the gap in Swift’s standard library — Foundation.UUID only generates UUID v4 — and demonstrate packages that bring RFC 9562 UUID v7 to Swift apps and Vapor services. See What is a UUID for the specification background.

UUID v7 generation in Swift

import Foundation

// Minimal UUID v7 generator in pure Swift
func uuidV7() -> UUID {
  let ms   = UInt64(Date().timeIntervalSince1970 * 1000)
  var bytes = [UInt8](repeating: 0, count: 16)

  // 48-bit timestamp in bytes 0–5
  bytes[0] = UInt8((ms >> 40) & 0xFF)
  bytes[1] = UInt8((ms >> 32) & 0xFF)
  bytes[2] = UInt8((ms >> 24) & 0xFF)
  bytes[3] = UInt8((ms >> 16) & 0xFF)
  bytes[4] = UInt8((ms >>  8) & 0xFF)
  bytes[5] = UInt8( ms        & 0xFF)

  // 12 random bits + version 7
  var rand = [UInt8](repeating: 0, count: 10)
  _ = SecRandomCopyBytes(kSecRandomDefault, 10, &rand)
  bytes[6] = (rand[0] & 0x0F) | 0x70  // version 7
  bytes[7] =  rand[1]
  // variant bits
  bytes[8] = (rand[2] & 0x3F) | 0x80
  bytes[9..<16] = rand[3..<10]

  let uuid = NSUUID(uuidBytes: bytes)
  return uuid as UUID
}

SwiftData model with UUID v7

import SwiftData
import Foundation

@Model
final class Order {
  @Attribute(.unique) var id: UUID
  var customerId: UUID
  var total:      Double
  var status:     String

  init(customerId: UUID, total: Double) {
    self.id         = uuidV7()  // UUID v7 — time-ordered
    self.customerId = customerId
    self.total      = total
    self.status     = "pending"
  }

  // Extract creation time from UUID v7
  var createdAt: Date {
    var bytes = [UInt8](repeating: 0, count: 16)
    (id as NSUUID).getBytes(&bytes)
    let ms = UInt64(bytes[0]) << 40
            | UInt64(bytes[1]) << 32
            | UInt64(bytes[2]) << 24
            | UInt64(bytes[3]) << 16
            | UInt64(bytes[4]) << 8
            | UInt64(bytes[5])
    return Date(timeIntervalSince1970: Double(ms) / 1000)
  }
}

Vapor route with UUID v7

import Vapor
import Fluent

func routes(_ app: Application) throws {
  app.post("orders") { req async throws -> Order in
    struct CreateBody: Content {
      let customerId: UUID
      let total: Double
    }
    let body  = try req.content.decode(CreateBody.self)
    let order = Order(customerId: body.customerId, total: body.total)
    try await order.create(on: req.db)
    return order
  }
}

Further reading

External references

Frequently asked questions

How do I generate UUID v7 in Swift?

Swift's Foundation.UUID does not generate UUID v7 natively as of Swift 5.10. Use the swift-uuid or UUIDv7 Swift package to generate UUID v7, then wrap it in Foundation.UUID(uuidString:). Alternatively, construct the 128-bit value manually: 48-bit timestamp + version bits + 74 random bits. See What is a UUID.

Can SwiftData use UUID v7 as a model ID?

Yes. SwiftData models use @Attribute(.unique) with a UUID property. Replace UUID() (UUID v4) with your UUID v7 generator in the model initializer. SwiftData stores UUIDs as 16-byte binary — time-ordering in UUID v7 improves SQLite B-tree locality for SwiftData's underlying store. See UUID in SQLite.

Does UUID v7 work with CloudKit sync?

CloudKit record IDs are strings — UUID v7 strings are valid CloudKit record names. Time-ordered UUIDs improve conflict resolution heuristics: a record with a later UUID v7 was created later, useful for last-write-wins merge policies. UUID v7 also provides a shared identifier between a local SwiftData record and its CloudKit counterpart.