Skip to content

About

Insert, delete, and reorder SwiftData query results through a projected collection.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

swift-data-writable logo

swift-data-writable

Insert, delete, and reorder SwiftData query results through a projected collection.

CI Swift 6.3+ Platforms: iOS 18+ | macOS 15+ | tvOS 18+ | watchOS 11+ License: Apache-2.0 WITH Swift-exception

Overview · Quick look · Install · Usage · Requirements · Documentation · Contributing · License

Overview

Give a SwiftUI list a write companion while @Query remains its read source. @Writable routes edits through the view’s ModelContext, and sorted moves reuse the configured ordering field; the usage guide explains saves, relationships, and limits.

Quick look

With the Person model from the usage guide:

import SwiftData
import SwiftDataWritable
import SwiftUI
struct PeopleView: View {
  @Writable @Query(sort: \Person.name) var persons: [Person]
  var body: some View {
    List {
      ForEach(persons) { Text($0.name) }.onDelete(perform: $persons.remove)
      Button("Add") { $persons.append(Person(name: "New")) }
    }
  }
}

Install

Add the package and the SwiftDataWritable product to Package.swift:

dependencies: [
  .package(
    url: "https://github.com/swift-library/swift-data-writable.git",
    .upToNextMinor(from: "0.1.1")
  ),
],
targets: [
  .target(
    name: "YourApp",
    dependencies: [
      .product(name: "SwiftDataWritable", package: "swift-data-writable"),
    ]
  ),
]

In an Xcode project, add the same URL with File > Add Package Dependencies and choose the Up to Next Minor Version rule. @Writable is a Swift macro, so Xcode asks you to trust the package before its first build.

Note

swift-data-writable is pre-1.0. Minor releases may include source-breaking changes, so depend on it with .upToNextMinor(from:).

Usage

Attach @Writable to a query or model property, then use its projected companion for edits. Call save() explicitly or choose an autosave policy.

The usage guide covers the full example, property shapes, query collections, relationships, save errors, transactions, and actor ownership.

Requirements

  • Swift 6.3 or later
  • iOS 18 or later, macOS 15 or later, tvOS 18 or later, and watchOS 11 or later

The compiler minimum follows the latest stable Xcode used by shared CI, currently Xcode 26.6. The current system maintenance window is iOS 18, 26, and 27; macOS 15, 26, and 27; tvOS 18, 26, and 27; and watchOS 11, 26, and 27. The macro implementation uses SwiftSyntax 602, and Package.resolved records the revision used for validation. The release reference describes compatibility and maintenance: the latest released line receives fixes, and older-line backports are evaluated per issue.

Documentation

  • Usage guide: examples, behavior, and limits.
  • Writable combinations: every supported and rejected property shape, its generated surface, and the meaning of each method.
  • Architecture: targets, the macro and runtime boundary, and save, relationship, and reordering semantics.
  • API documentation: the DocC catalog.
  • Release: release facts and mechanics; version rules are in VERSIONING.
  • Changelog

Contributing

Read CONTRIBUTING.md before opening a pull request, and run the local validation commands there before submitting changes. Report vulnerabilities through the private route in SECURITY.md.

License

swift-data-writable is available under the Apache License 2.0 with the Swift Runtime Library Exception. See LICENSE.txt and NOTICE. NOTICE also records SwiftSyntax, a package dependency whose own license and notices remain in its package.

About

Insert, delete, and reorder SwiftData query results through a projected collection.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages