I'm trying to implement a coreData class to handle all the database queries - The problem is that I'm getting an error saying that "value of type 'dataModel' has no member 'context' which is on line 15
My current code is:
import UIKit
import CoreData
class dataModel: NSObject {
override init() {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Item")
request.returnsObjectsAsFaults = false
}
func findItems() {
do {
let results = try self.context.fetch(self.request)
if results.count > 0 {
for result in results {
if let itemID = result.objectWithID(id) as? Item {
print(itemID)
}
if let itemName = result.value(forKey: "title") as? String {
print(itemName)
}
if let itemDesc = result.value(forKey: "content") as? String {
print(itemDesc)
}
}
}
} catch {
print("APP: Error getting data \(error.localizedDescription)")
}
}
}
I think I'm in the right direction, just can't seem to get this area to work.
Thanks