marcoarment / Blackbird

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@BlackbirdColumnObserver example doesn't work

ajayjapan opened this issue · comments

This example does not work.

struct MyView: View {
     // title will be of type: String?
     @BlackbirdColumnObserver(\MyModel.$title, primaryKey: 123) var title

     var body: some View {
         Text(title ?? "Loading…")
     }
}

The error I am getting is:
Value of optional type 'String?' must be unwrapped to a value of type 'String'

Weirdly this seems to work by using a !:

struct MyView: View {
     // title will be of type: String?
     @BlackbirdColumnObserver(\MyModel.$title, primaryKey: 123) var title

     var body: some View {
         Text((title ?? "Loading…")!)
     }
}

I think this happens when the column is an optional already:

  @BlackbirdColumn public var title: String?

This results in:

     @BlackbirdColumnObserver(\MyModel.$title, primaryKey: 123) var title : String??

Related to: 2f15d7f