stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.7k stars 1.56k forks source link

@Binding problem with SQLite and SwiftUI #1096

Closed adamek314 closed 2 years ago

adamek314 commented 2 years ago

With the following code fragment:

import SwiftUI
import SQLite
import CoreLocation

struct StoresRoot: SwiftUI.View {

    @Binding var foodyState: FoodyState
    @Binding var currentReceipt: LedgersSQL
    @Binding var currentStore: StoresSQL

Xcode puts a "Unknown attribute 'Binding'" error at the end of each @Binding line

If I comment out the import SQLite line, the error goes away.

Is there a way to import SQLite.swift and SwiftUI in the same file, or do I have to get more stringent about separating my models and views?

macOS Monterey 12.1 Beta (21C5021h) Xcode Version 13.1 (13A1030d) SQLite.swift 0.13.0

adamek314 commented 2 years ago

Workaround, insert SwiftUI. between @ and Binding.

nathanfallet commented 2 years ago

It would be great to separate Views and Models (you can use a @StateObject ViewModel with @Published properties for example). In case you want to import both frameworks, you can of course differentiate Binding with SwiftUI.Binding and SQLite.Binding.