When I try to pass parameter to @FetchRequest, how to solve?

Here is my code ...

var accountType = "Account"

@FetchRequest(
  sortDescriptors: [NSSortDescriptor(keyPath: \JMAccount.displayOrder, ascending: true)]
, predicate: NSPredicate(format: "(hidden < %@) AND (type == %@)", argumentArray: [Int(1), accountType])
, animation: .default
)

private var items: FetchedResults<JMAccount>


Then Xcode report error below ...

"Cannot use instance member 'accountType' within property initializer; property initializers run before 'self' is available"


How can I solve this error ?

More info, I want to make multiple view with parameter to @FetchRequest. So I try to make variable for this parameter. If you have better idea, please suggest me.

Best to use:

lazy var accountType = "Account"

@FetchRequest(
  sortDescriptors: [NSSortDescriptor(keyPath: \.displayOrder, ascending: true)]
, predicate: NSPredicate(format: "(hidden < %@) AND (type == %@)", argumentArray: [1, accountType])
, animation: .default
)

private var items: FetchedResults<JMAccount>

or

@FetchRequest(
  sortDescriptors: [NSSortDescriptor(keyPath: \.displayOrder, ascending: true)]
, predicate: NSPredicate(format: "(hidden < %@) AND (type == %@)", argumentArray: [1, "Account"])
, animation: .default
)

private var items: FetchedResults<JMAccount>

Thank you for your reply. However for your first solution, Xcode still show the same error message. 2nd solution is work fine but it is not my solution for multiple view with parameter (accountType). I want to make multiple view with difference accountType by using same SwiftUI file (object). Do you have any more suggestion?

When I try to pass parameter to &#64;FetchRequest, how to solve?
 
 
Q