Swift Object Graph
The CoreModel target compiles under Embedded Swift, 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.
SWIFTPM_ENABLE_MACROS=0 swift build --swift-sdk swift-6.3.2-RELEASE_wasm-embedded
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:
Entity.entityName,attributes, andrelationshipshave no default implementation — implement them explicitly.Entity.init(from:)/encode()have no default Codable-derived implementation — implement them usingModelData.decode(_:forKey:)/.encode(_:forKey:)(seePersoninTests/CoreModelTests/TestModel.swiftfor the pattern).enum CodingKeys: CodingKey { ... }must declare an explicitStringraw value —enum CodingKeys: String, CodingKey { ... }— since Embedded Swift has noCodable/CodingKeysynthesis;CoreModelprovides its ownCodingKeyprotocol under Embedded that relies on the raw value.Model(entities: any Entity.Type...)is unavailable (calls a generic initializer through an existential); useModel(entities: [EntityDescription(entity: Person.self), ...])with concrete types instead.ModelStorage's genericEntity-based convenience methods (fetch<T>,insert<T>,delete<T>,count<T>) andViewContextare unavailable under Embedded (a compiler limitation inasyncdefault protocol-extension methods). Call theModelStorageprotocol requirements directly withModelData/ObjectID.UUID,Date,Data,URL, andDecimalare Foundation-free storage-layer replacements on platforms without Foundation — sufficient for round-tripping throughAttributeValue, not general-purpose Foundation substitutes.