Skip to content

Commit

Permalink
handling store db url
Browse files Browse the repository at this point in the history
  • Loading branch information
kvyatkovskys committed Feb 26, 2023
1 parent 642d64d commit e1eac4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
16 changes: 8 additions & 8 deletions Sources/KVKLogger/KVKLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ open class KVKLogger {
details: String?) {
let date = Date()
if isEnableSaveIntoDB {
let item = ItemLog(context: store.backgroundContext)
item.createdAt = date
item.status_ = status?.rawValue
item.logType = logType
item.type = type
item.details = details
item.items = items
item.data = data
let item = store.getNewItem()
item?.createdAt = date
item?.status_ = status?.rawValue
item?.logType = logType
item?.type = type
item?.details = details
item?.items = items
item?.data = data
store.save()
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/KVKLogger/KVKLoggerProxyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ struct KVKLoggerView_Previews: PreviewProvider {
newItem3.type = ItemLogType.network
newItem3.logType = KVKLogType.print
newItem3.items = "Test description network Test description network Test description network"
result.backgroundContext.saveContext()
result.save()
return Group {
KVKLoggerProxyView()
KVKLoggerProxyView()
Expand Down
6 changes: 6 additions & 0 deletions Sources/KVKLogger/KVKPersistenceСontroller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ struct KVKPersistenceСontroller {
backgroundContext = container.newBackgroundContext()
}

func getNewItem() -> ItemLog? {
guard container.persistentStoreDescriptions.first?.url != nil else { return nil }
return ItemLog(context: backgroundContext)
}

func save() {
guard container.persistentStoreDescriptions.first?.url != nil else { return }
backgroundContext.saveContext()
}

Expand Down

0 comments on commit e1eac4c

Please sign in to comment.