Hoşgeldin. Soru sormak veya cevaplamak için hemen üye ol.
0 oy
193 kez görüntülendi
ios development kategorisinde tarafından

Merhaba Arkadaşlar,

Uygulamada kullandığım fonksiyonu aşağıda paylaşıyorum sadece coredata daki datalara erişmeye onları String bir değişkene atmaya çalışıyorum ama bir türlü olmadı.

func selectUser(){

        let fetchRequest = NSFetchRequest(entityName: "User")

        let appdel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

        let context:NSManagedObjectContext = appdel.managedObjectContext

        do {

            var results = try context.executeFetchRequest(fetchRequest) as! [User]

            if (results.count > 0) {

 

                ad = results[0].description

                soyad = results[1].description

                akvkod = results[2].description

                

            } else {

                print("No User")

            }

        } catch let error as NSError {

            // failure

            print("Fetch failed: \(error.localizedDescription)")

        }

    }

 

 

Dönen Hata ise aşağıdaki gibi;

<User: 0x175681f0> (entity: User; id: 0x17560700 <x-coredata://DE1F9516-22DB-4F18-B516-A73B79CB27AE/User/p5> ; data: <fault>)

1 cevap

+1 oy
tarafından
 
En İyi Cevap

Cevabı bulmam için galiba soruyu buraya sormam yeterli oluyor :) Hatamı düzelttim paylaşayım dedim arkadaşlar happy coding :)

func selectUser(){

    let fetchRequest = NSFetchRequest(entityName: "User")
    let appdel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    let context:NSManagedObjectContext = appdel.managedObjectContext

    do {
        let results = try context.executeFetchRequest(fetchRequest) as! [User]
        if (results.count > 0) {

            for result in results as [NSManagedObject] {


                ad = (result.valueForKey("user_ad"))! as! String
                print(ad)
            }

        } else {
            print("No Users")
        }
    } catch let error as NSError {
        // failure
        print("Fetch failed: \(error.localizedDescription)")
    }


}
...