c_cpp 数据库操作

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 数据库操作相关的知识,希望对你有一定的参考价值。


        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
    
}

以上是关于c_cpp 数据库操作的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 【18】基本鼠标操作

c_cpp 字符串操作

c_cpp Ç链表操作

c_cpp 位操作

c_cpp 位操作

c_cpp 位操作