mergesort / Boutique

✨ A magical persistence library (and so much more) for state-driven iOS and Mac apps ✨
https://build.ms/boutique/docs
MIT License
899 stars 43 forks source link

"No exact matches in call to initializer" error when creating a store #45

Closed flexaddicted closed 1 year ago

flexaddicted commented 1 year ago

Hi all,

Using the following code, I'm not able to compile the app since receiving the error:

No exact matches in call to initializer

A type mismatch should be the cause of the problem but I cannot find any solution.

Any suggestions?

Thanks, Lorenzo

import Foundation
import Boutique
import FirebaseFirestoreSwift

struct Document: Codable, Equatable, Identifiable {
    @DocumentID var id: String?
    let title: String
    let index: Int
    let detailItems: [DetailItem]
}

struct DetailItem: Codable, Equatable, Hashable {
    let title: String
    let pdfUrl: URL
}

extension Store where Item == Document {
    static let documentsStore = Store<Document>( // No exact matches in call to initializer
        storage: SQLiteStorageEngine.default(appendingPath: "Documents")
    )
}
flexaddicted commented 1 year ago

The problem is with @DocumentID.

Here's a sample solution:

struct Document: Codable, Equatable, Identifiable {
    @DocumentID var documentId: String?
    let title: String
    let index: Int
    let detailItems: [DetailItem]

    var id: String {
        documentId ?? UUID().uuidString
    }
}
flexaddicted commented 1 year ago

Closing the issue since resolved.