|
99 | 99 | repeat (each T2).PrimaryKey.QueryOutput: IdentifierStringConvertible, |
100 | 100 | repeat (each T2).TableColumns.PrimaryColumn: WritableTableColumnExpression |
101 | 101 | { |
| 102 | + @Dependency(\.context) var context |
102 | 103 | let containerIdentifier = |
103 | 104 | containerIdentifier |
104 | 105 | ?? ModelConfiguration(groupContainer: .automatic).cloudKitContainerIdentifier |
105 | | - |
| 106 | + ?? (context == .preview ? "preview" : nil) |
106 | 107 | var allTables: [any SynchronizableTable] = [] |
107 | 108 | var allPrivateTables: [any SynchronizableTable] = [] |
108 | 109 | for table in repeat each tables { |
|
113 | 114 | } |
114 | 115 | let userDatabase = UserDatabase(database: database) |
115 | 116 |
|
116 | | - @Dependency(\.context) var context |
117 | 117 | guard context == .live |
118 | 118 | else { |
119 | 119 | let privateDatabase = MockCloudDatabase(databaseScope: .private) |
|
325 | 325 | : URL(filePath: metadatabase.path).lastPathComponent |
326 | 326 | let attachedMetadatabaseName = |
327 | 327 | URL(string: attachedMetadatabasePath)?.lastPathComponent ?? "" |
328 | | - if metadatabaseName != attachedMetadatabaseName { |
| 328 | + @Dependency(\.context) var context |
| 329 | + if metadatabaseName != attachedMetadatabaseName |
| 330 | + && !(context == .preview && attachedMetadatabaseName.isEmpty) |
| 331 | + { |
329 | 332 | throw SchemaError( |
330 | 333 | reason: .metadatabaseMismatch( |
331 | 334 | attachedPath: attachedMetadatabasePath, |
|
337 | 340 | """ |
338 | 341 | ) |
339 | 342 | } |
340 | | - |
341 | 343 | } else { |
342 | 344 | try #sql( |
343 | 345 | """ |
|
2151 | 2153 | /// - Parameter containerIdentifier: The identifier of the CloudKit container used to |
2152 | 2154 | /// synchronize data. Defaults to the value set in the app's entitlements. |
2153 | 2155 | public func attachMetadatabase(containerIdentifier: String? = nil) throws { |
| 2156 | + @Dependency(\.context) var context |
2154 | 2157 | let containerIdentifier = |
2155 | 2158 | containerIdentifier |
2156 | 2159 | ?? ModelConfiguration(groupContainer: .automatic).cloudKitContainerIdentifier |
| 2160 | + ?? (context == .preview ? "preview" : nil) |
2157 | 2161 |
|
2158 | 2162 | guard let containerIdentifier else { |
2159 | 2163 | throw SyncEngine.SchemaError.noCloudKitContainer |
|
0 commit comments