Skip to content

Commit

Permalink
feat(pluto): prepare core data stack for swift package
Browse files Browse the repository at this point in the history
Fixes ATL-2354
  • Loading branch information
goncalo-frade-iohk committed Dec 1, 2022
1 parent 159ffa8 commit 063c5bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ let package = Package(
.target(
name: "Pluto",
dependencies: ["Domain"],
path: "Pluto/Sources"
path: "Pluto/Sources",
resources: [.process("Resources/PrismPluto.xcdatamodeld")]
),
.testTarget(
name: "PlutoTests",
Expand Down
19 changes: 10 additions & 9 deletions Pluto/Sources/Helpers/CoreData/CoreDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public final class CoreDataManager {
if let mdl = CoreDataManager._model { return mdl }
let modelPath: URL
switch setup.modelPath {
case let .storeName(name):
guard let modelURL = Bundle(for: type(of: self)).url(forResource: name, withExtension: "momd") else {
case let .storeName(name, bundle):
guard let modelURL = bundle.url(forResource: name, withExtension: "momd") else {
fatalError("Unable to Find Data Model")
}
modelPath = modelURL
Expand Down Expand Up @@ -102,7 +102,7 @@ public final class CoreDataManager {
private func persistentStoreUrl() -> URL {
let modelName: String
switch setup.modelPath {
case let .storeName(value):
case let .storeName(value, _):
modelName = value
case let .storeURL(value):
modelName = value.deletingPathExtension().lastPathComponent
Expand All @@ -125,28 +125,29 @@ public extension CoreDataManager {
}

public enum ModelPath {
case storeName(String)
case storeName(String, Bundle = ModelKit.bundle)
case storeURL(URL)
}

// swiftlint:disable lower_acl_than_parent

public let modelPath: ModelPath
public let storeType: StoreType

public init(modelPath: ModelPath, storeType: StoreType) {
self.modelPath = modelPath
self.storeType = storeType
}

// swiftlint:enable lower_acl_than_parent
}
}

// Helper so the core data model can be found
public enum ModelKit {
public static let bundle = Bundle.module
}

private extension CoreDataManager.CoreDataSetup {
var modelName: String {
switch modelPath {
case let .storeName(name):
case let .storeName(name, _):
return name
case let .storeURL(url):
return url.deletingPathExtension().lastPathComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21279" systemVersion="21G83" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier=""/>

0 comments on commit 063c5bb

Please sign in to comment.