Cannot create an SQL store with a nil URL #275

Closed
opened 2025-12-29 15:28:04 +01:00 by adam · 3 comments
Owner

Originally created by @seanliu1 on GitHub (May 29, 2019).

This is my interface looks like

    init <T: StorageInterface>(storage: T, persistenceManager: MediaPersistenceManager) {
        do {
            try dataStack.addStorageAndWait(storage)
        } catch {
            Logger.shared.log(error: error, message: "Failed to setup CoreData")
        }
}

I want to do dependency injection, then for test, I can provide in-memory storage, in production app I can use local storage.

However I start to see once I change it to that way
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an SQL store with a nil URL.

It looks like we always pass nil to finalURL if it comes from StorageInterface, should we have factory method based on input type to determine which constructor to use?

 _ = try self.createPersistentStoreFromStorage(
                    storage,
                    finalURL: nil,
                    finalStoreOptions: storage.storeOptions
Originally created by @seanliu1 on GitHub (May 29, 2019). This is my interface looks like ``` init <T: StorageInterface>(storage: T, persistenceManager: MediaPersistenceManager) { do { try dataStack.addStorageAndWait(storage) } catch { Logger.shared.log(error: error, message: "Failed to setup CoreData") } } ``` I want to do dependency injection, then for test, I can provide in-memory storage, in production app I can use local storage. However I start to see once I change it to that way *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an SQL store with a nil URL. It looks like we always pass nil to finalURL if it comes from StorageInterface, should we have factory method based on input type to determine which constructor to use? ``` _ = try self.createPersistentStoreFromStorage( storage, finalURL: nil, finalStoreOptions: storage.storeOptions ```
adam added the question label 2025-12-29 15:28:04 +01:00
adam closed this issue 2025-12-29 15:28:04 +01:00
Author
Owner

@JohnEstropia commented on GitHub (May 29, 2019):

Use <T: LocalStorage> instead of <T: StorageInterface>

@JohnEstropia commented on GitHub (May 29, 2019): Use `<T: LocalStorage>` instead of `<T: StorageInterface>`
Author
Owner

@seanliu1 commented on GitHub (May 29, 2019):

how to pass InMemoryStore if we wanna to use in memory storage for unit test, since InMemoryStore does not conform to LocalStorage. Both LocalStore and InMemoryStore conforms to StorageInterface.

@seanliu1 commented on GitHub (May 29, 2019): how to pass InMemoryStore if we wanna to use in memory storage for unit test, since InMemoryStore does not conform to LocalStorage. Both LocalStore and InMemoryStore conforms to StorageInterface.
Author
Owner

@JohnEstropia commented on GitHub (May 29, 2019):

I see. If you need both then you need to implement the overloads for both.

init<T: StorageInterface>(...)
init<T: LocalStorage>(...)
@JohnEstropia commented on GitHub (May 29, 2019): I see. If you need both then you need to implement the overloads for both. ```swift init<T: StorageInterface>(...) init<T: LocalStorage>(...) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#275