"'>' is not a postfix unary operator" when using NSFetchedResultsController

Hi

As title, when trying to use NSFetchedResultsController I get the following error:

'>' is not a postfix unary operator

class WindowController: NSObject, ObservableObject {
    
    @Published var spans: [Span] = []

    private let controller = NSFetchedResultsController<Windows>

    init(context: NSManagedObjectContext) {
    controller = NSFetchedResultsController(fetchRequest: Windows.fetchRequest(), managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
    }
}

I can get it to work by changing it to

private var controller = NSFetchedResultsController<Windows>() 

but I'm wondering what's going on with the original code.

You need to instantiate the controller.

With present code you assign the type NSFetchedResultsController<Windows> and not create an instance as in NSFetchedResultsController<Windows>()

Hence the error (which is not very explicit though but compiler tries to interpret what you wrote).

"'&gt;' is not a postfix unary operator" when using NSFetchedResultsController
 
 
Q