I am presently making my first steps using Core Data, with Swift. Even though I have quite a bit of experience with Core Data, I have close to none with Swift.
Here is what I want to do: make a function which is going to compute the number of records in an entity, from the name of the entity.
Something like this:
func countEntity (name:String) -> Int {
var theNumberOfRecords:Int
let fetchRequest = NSFetchRequest(entityName:name)
// What I have tried at this point only gives error messages …..
return theNumberOfRecords
}
It should not be rocket science. But I have not been able to make something work after various trial and errors. How should I write the necessary code? I presume it should be no more that a few lines. The one I have in Objective C is 6 lines.