let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
let request = NSFetchRequest(entityName: "AppController")
request.returnsObjectsAsFaults = false
do {
let result = try context.executeFetchRequest(request)
if (result.count > 0) {
let AppController = result[0] as! NSManagedObject
print("\(AppController.valueForKey("sonGuncelleme"))")
}
} catch {
let fetchError = error as NSError
print(fetchError)
}
func updateSelectedInfoCompany (predicate:NSPredicate, isSelected:String) -> Bool {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext
let fetchRequest = NSFetchRequest(entityName: "Company")
fetchRequest.predicate = predicate
do {
let results = try managedContext.executeFetchRequest(fetchRequest)
let company = results[0] as! NSManagedObject
company.setValue(isSelected, forKey: "isSelected")
try company.managedObjectContext?.save()
return true
} catch let error as NSError {
print("Could not fetch \(error), \(error.userInfo)")
return false
}
}
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
var newUser = NSEntityDescription.insertNewObjectForEntityForName("AppController",
inManagedObjectContext: context) as NSManagedObject
newUser.setValue("Rob", forKey: "sonGuncelleme")
do {
try newUser.managedObjectContext?.save()
} catch {
let saveError = error as NSError
print(saveError)
}
//1- Core data da entity oluştur. içine entity class bölümünü mutlaka doldur. sağ taraftaki.
//2- Class oluştur
@objc(DoluBeacon)
class DoluBeacon: NSManagedObject {
@NSManaged var id: Int
@NSManaged var plaka: String
@NSManaged var girisZamani: String
@NSManaged var cikisZamani: String
@NSManaged var major: Int
@NSManaged var minor: Int
}
//3- nesneyi oluştur.
let managedObject = NSEntityDescription.insertNewObjectForEntityForName("DoluBeacon",
inManagedObjectContext: context) as! DoluBeacon
//4- ile nesneyi doldur
managedObject.id = id.toInt()!
let predicate = NSPredicate(format: "beaconMajor == %@ and beaconMinor == %@ and type == 'Text'", self.gelenMajor, self.gelenMinor)
import CoreData
class Person: NSManagedObject {
@NSManaged var name : NSString
}