Skip to content

Commit

Permalink
refactor tip kit and persistent container if debug or release (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
erolburak authored May 16, 2024
1 parent 6a48a4b commit c5461e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions BobbysNews/Presentation/ContentViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ final class ContentViewModel: Sendable {
self.deleteTopHeadlinesUseCase = deleteTopHeadlinesUseCase
self.fetchTopHeadlinesUseCase = fetchTopHeadlinesUseCase
self.readTopHeadlinesUseCase = readTopHeadlinesUseCase
#if DEBUG
return
#else
configureTipKit()
#endif
}

func onAppear(selectedCountry: String) {
Expand Down Expand Up @@ -161,10 +165,8 @@ final class ContentViewModel: Sendable {

private func configureTipKit() {
Task {
if ProcessInfo().environment["XCTestConfigurationFilePath"] == nil {
try? Tips.configure([.displayFrequency(.immediate),
.datastoreLocation(.groupContainer(identifier: "com.burakerol.BobbysNews"))])
}
try? Tips.configure([.displayFrequency(.immediate),
.datastoreLocation(.groupContainer(identifier: "com.burakerol.BobbysNews"))])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public final class PersistenceController {
let managedObjectModel = NSManagedObjectModel(contentsOf: moduleUrl) else {
fatalError("Error initializing managed object model with module url!")
}
/// Disable cloud kit database if test scheme is running
let isTestScheme = ProcessInfo().environment["XCTestConfigurationFilePath"] != nil
container = isTestScheme ? NSPersistentContainer(name: "BobbysNews",
managedObjectModel: managedObjectModel) : NSPersistentCloudKitContainer(name: "BobbysNews",
managedObjectModel: managedObjectModel)
#if DEBUG
container = NSPersistentContainer(name: "BobbysNews",
managedObjectModel: managedObjectModel)
#else
NSPersistentCloudKitContainer(name: "BobbysNews",
managedObjectModel: managedObjectModel)
#endif
container.loadPersistentStores { _, error in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
Expand Down

0 comments on commit c5461e4

Please sign in to comment.