Swift Object Graph
Swift 6.0 or later, macOS 10.15, iOS 13, tvOS 13, and watchOS 6.
InMemoryStorage, InMemoryModelStorage, and InMemoryViewContext are the exception: they serialize access to their shared backing with Synchronization.Mutex, which is not back-deployed, so on Apple platforms they require macOS 15, iOS 18, tvOS 18, watchOS 11, or visionOS 2. Everything else in CoreModel — the schema types, predicates, and the ModelStorage/ViewContext protocols — is available at the package's own deployment targets, as are third-party backends such as SQLite and MongoDB. Linux, Windows, Android, and WebAssembly have no such restriction.
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.