Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Sep 30, 2023
2 parents 82846f7 + 82b77f6 commit b4991dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Sources/ManagedModels/Container/NSPersistentContainer+Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ extension NSPersistentContainer {
//@MainActor - TBD :-)
@inlinable
public var mainContext : NSManagedObjectContext { viewContext }

@inlinable
public var configurations : [ NSPersistentStoreDescription ] {
persistentStoreDescriptions
}

convenience
public init(for model : NSManagedObjectModel,
Expand All @@ -29,11 +34,17 @@ extension NSPersistentContainer {
return merged ?? model
}()

var configurations = configurations
if configurations.isEmpty {
configurations.append(Self.defaultConfiguration)
}

// TBD: Is this correct? It is the container name, not the configuration
// name?
let firstName = configurations.first(where: { !$0.name.isEmpty })?.name
?? "ManagedModels"

assert(!configurations.isEmpty)
self.init(
name: firstName,
managedObjectModel: combinedModel
Expand Down Expand Up @@ -61,6 +72,14 @@ extension NSPersistentContainer {
viewContext.automaticallyMergesChangesFromParent = true
}

private static var defaultConfiguration : ModelConfiguration {
.init(
path: nil, name: nil, schema: nil,
isStoredInMemoryOnly: false, allowsSave: true,
groupAppContainerIdentifier: nil, cloudKitContainerIdentifier: nil,
groupContainer: .none, cloudKitDatabase: .none
)
}
}

public extension NSPersistentContainer {
Expand Down
4 changes: 2 additions & 2 deletions Tests/ManagedModelMacrosTests/ManagedModelMacrosTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ final class ModelMacroTests: XCTestCase {
"""
))

#if true
#if false
print("Exploded:---\n")
print(explodedSource)
print("\n-----")
Expand Down Expand Up @@ -360,7 +360,7 @@ final class ModelMacroTests: XCTestCase {
"""
))

#if true
#if false
print("Exploded:---\n")
print(explodedSource)
print("\n-----")
Expand Down

0 comments on commit b4991dc

Please sign in to comment.