HomeiOS Developmentios - outline Predicate for @FetchRequest base on different initialized property...

ios – outline Predicate for @FetchRequest base on different initialized property in SwiftUI?


That is my definition for fetch request:

import SwiftUI

struct CurrentMonthView: View {
    non-public var month: Month
    @FetchRequest(
        sortDescriptors: [SortDescriptor(.date, order: .forward)],
        predicate: NSPredicate(format: "month.identifier == %@", month.identifier), //❌
        animation: .easeInOut
    ) var companies: FetchedResults
    init(month: Month) {
        self.month = month
    }
    var physique: some View {
        ForEach(companies) { service in }
    }
}

The ❌ is the next: Can't use occasion member 'month' inside property initializer; property initializers run earlier than 'self' is obtainable.

What’s the appropriate technique to outline @FetchRequest to make it working in above conditions? I believe it is vitally widespread.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments