Skip to content

Commit fb5a842

Browse files
committed
Document Embedded Swift support
1 parent 227e2fe commit fb5a842

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,20 @@ Swift Object Graph
1313
- CoreData
1414
- [SQLite](https://github.com/PureSwift/CoreModel-SQLite)
1515
- [MongoDB](https://github.com/PureSwift/CoreModel-MongoDB)
16+
17+
## Embedded Swift
18+
19+
The `CoreModel` target compiles under [Embedded Swift](https://docs.swift.org/embedded/documentation/embedded), starting with WebAssembly (`wasm32-unknown-none-wasm` / `wasm32-unknown-wasip1` via the embedded Swift SDK). `CoreDataModel` remains a Foundation/CoreData-only target and is unaffected.
20+
21+
```
22+
SWIFTPM_ENABLE_MACROS=0 swift build --swift-sdk swift-6.3.2-RELEASE_wasm-embedded
23+
```
24+
25+
Macros must be disabled (`SWIFTPM_ENABLE_MACROS=0`) since `swift-syntax` isn't available under Embedded. This means a few things `@Entity` normally generates aren't available and must be written by hand:
26+
27+
- `Entity.entityName`, `attributes`, and `relationships` have no default implementation — implement them explicitly.
28+
- `Entity.init(from:)` / `encode()` have no default Codable-derived implementation — implement them using `ModelData.decode(_:forKey:)` / `.encode(_:forKey:)` (see `Person` in `Tests/CoreModelTests/TestModel.swift` for the pattern).
29+
- `enum CodingKeys: CodingKey { ... }` must declare an explicit `String` raw value — `enum CodingKeys: String, CodingKey { ... }` — since Embedded Swift has no `Codable`/`CodingKey` synthesis; `CoreModel` provides its own `CodingKey` protocol under Embedded that relies on the raw value.
30+
- `Model(entities: any Entity.Type...)` is unavailable (calls a generic initializer through an existential); use `Model(entities: [EntityDescription(entity: Person.self), ...])` with concrete types instead.
31+
- `ModelStorage`'s generic `Entity`-based convenience methods (`fetch<T>`, `insert<T>`, `delete<T>`, `count<T>`) and `ViewContext` are unavailable under Embedded (a compiler limitation in `async` default protocol-extension methods). Call the `ModelStorage` protocol requirements directly with `ModelData`/`ObjectID`.
32+
- `UUID`, `Date`, `Data`, `URL`, and `Decimal` are Foundation-free storage-layer replacements on platforms without Foundation — sufficient for round-tripping through `AttributeValue`, not general-purpose Foundation substitutes.

0 commit comments

Comments
 (0)