0

i need to fetch IF there is anything in the sqlite in a UITableview return nil if not "and not crash"

var fetchedResultsController: NSFetchedResultsController{

        var fetched = Profil.fetchAllSortedBy("hostname", ascending: true, withPredicate: nil, groupBy: nil, delegate: self)
        return self.fetchedResultsController
}

how is it possible to fetch and and if it's nil it wont return anything ?

i tried this :

    var fetchedResultsController: NSFetchedResultsController{

    if _fetchedResultsController != nil {
                    return _fetchedResultsController!
                    }


        _fetchedResultsController = Profil.fetchAllSortedBy("hostname", ascending: true, withPredicate: nil, groupBy: nil, delegate: self)

        return _fetchedResultsController!


}
        var _fetchedResultsController: NSFetchedResultsController? = nil

but it returns in both cases this error :

 xxx[8708:637429] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[xxx.Profil fetchAllSortedBy:ascending:withPredicate:groupBy:delegate:]: unrecognized selector sent to class 0x107b1eab0'

here's the screenshot on how things are set up

before after enter image description here enter image description here

KennyVB
  • 745
  • 2
  • 9
  • 26
  • I have had a similar issue before with Magical Record and Swift and the actually problem was the `NSManagedObject` files i.e your `Profil.swift` file, if you have in fact created them as `.swift` files I would suggest generating them again as Objective-C files, i.e `Profil.h` and `Profil.m` – sbarow Oct 16 '14 at 10:08
  • @sbarow hmm, i just tried deleting the Profile.swift file and regenerate them a Objc file. no dice still.. still throws the same error at me – KennyVB Oct 16 '14 at 10:18
  • Have you prefixed the entities class name with the module name? Compare http://stackoverflow.com/questions/25076276/unabled-to-find-specific-subclass-of-nsmanagedobject. – Martin R Oct 16 '14 at 10:54
  • @MartinR hmm, i'm not sure what you mean ?? i've posted some pictures – KennyVB Oct 16 '14 at 13:00
  • @KennyVB: The Core Data class should be "YourAppName.Profil" as stated in the documentation and explained in the other thread. Alternatively, you can mark the generated Core Data class with `@objc(Profil)` (also explained in an answer to the that thread). – Martin R Oct 16 '14 at 13:02
  • @MartinR ahh now i see. well done that, but still no dice... still reports the same error – KennyVB Oct 16 '14 at 13:05

0 Answers0