Home > Software design >  iOS SwiftUI - Binding custom array error: Unexpected initializer in pattern; did you mean to use �
iOS SwiftUI - Binding custom array error: Unexpected initializer in pattern; did you mean to use �

Time:11-29

I need to pass an array to a view:

@Binding var memes: [MemeModel]()

I get the error

Unexpected initializer in pattern; did you mean to use '='?

why and how to fix this??

CodePudding user response:

[MemeModel]() is an initialized, empty array of MemeModels. Try deleting the () to indicate the type (rather than provide an actual object). Depending on what else is going on in the code, you may need to write @Binding var memes = [MemeModel]() to actually assign something to this variable (note that here, the type is implicitly specified).

  • Related