gpt4 book ai didi

swift - 核心数据条件

转载 作者:行者123 更新时间:2023-11-28 08:14:42 25 4
gpt4 key购买 nike

我需要添加一个 Core Data 条件,我该怎么做? .如果记录处于这种情况,则“sonuc”变量将为真

核心数据模型:

enter image description here

If "kullaniciadi" is "emre" and "otogiris" is "1" then the "sonuc" will be true

func getContext () -> NSManagedObjectContext {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if #available(iOS 10.0, *) {
return appDelegate.persistentContainer.viewContext
} else {
return DatabaseController.managedObjectContext
}
}



func otomatikGirisKontrol() -> Bool
{
var sonuc = false
let fetchRequest:NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "Kullanicilar")
fetchRequest.returnsObjectsAsFaults = false
do{
let results = try getContext().fetch(fetchRequest)
if results.count > 0
{
sonuc = true
}
else
{
sonuc = false
}

}
catch
{

}
return (sonuc)
}

最佳答案

使用 NSPredicate 只获取符合您条件的 Kullaniciar 对象:

let fetchRequest = ...

let kullaniciadi = "emre"
let otogiris = "1"
let predicate = NSPredicate(format: "kullaniciadi = %@ AND otogiris = %@", kullaniciadi, otogiris)

request.predicate = predicate

//... execute fetch request

关于swift - 核心数据条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42873187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com