1

although i am new to swift, i've experience with both core data and fetched results controllers. so, i am perplexed that when i compile the code below, i get an error "Use of undeclared type 'NSFetchedResultsController'"

i looked inside the CoreData framework which i added to my project, and NSFetchedResultsController is NOT present. i tried deleting and reinstalliing Xcode (version 7.3.1), on the assumption that the swift support was out of date, but no joy. i've found numerous articles about the "Use of undeclared type" error ... caused by reference to an instance or a custom framework declared incorrectly. numerous other articles describing in detail how to use a NSFetchedResultsController in swift code. no help anywhere have looked, nothing about an apple framework missing a well documented class

anybody have a solution?

my code:

import CoreData
import AppKit

class MyViewController: NSViewController, NSTableViewDataSource {

    @IBOutlet weak var tableView: NSTableView?

    let fetchedResultsController: NSFetchedResultsController = {
        var request: NSFetchRequest = NSFetchRequest(entityName: "ZIdea")
        let f: NSFetchedResultsController = NSFetchedResultsController(fetchRequest: request, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil);
        f.delegate = self

        return f
    }()

}
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
  • 1
    Check this question: http://stackoverflow.com/q/2429607/433373 and this one: http://stackoverflow.com/q/21215619/433373 - Looks like there's no `NSFetchedResultsController` in OSX? – Nicolas Miari Jul 08 '16 at 01:32
  • (I just found out myself; I never tried to use CoreData on the Mac) – Nicolas Miari Jul 08 '16 at 01:33

1 Answers1

1

As mentioned in the comments, NSFetchedResultsController is not available on macOS yet, however it will be introduced in 10.12 Sierra.

A suitable replacement is NSArrayController in conjunction with Cocoa Bindings.

vadian
  • 274,689
  • 30
  • 353
  • 361
  • yeah, thanks folks! i was just about to add a comment about OS X. vadian, i like your suggestion about NSArrayController and i see a link about it in NicolasMiari's comment – Jonathan Sand Jul 08 '16 at 05:06