CoreData - Query !!!

PHOTO EMBED

Fri Apr 12 2024 12:07:04 GMT+0000 (Coordinated Universal Time)

Saved by @Saurabh_Lodhi #swift #coredata

let fetchRequest: NSFetchRequest<UserModel_CD> = UserModel_CD.fetchRequest()
//Query on which basic data will be found from coreData
fetchRequest.predicate = NSPredicate(format: "email == %@ && password == %@", email, password)  

//This query in SQl looks like -
//SELECT * FROM Users WHERE email = 'user@example.com' AND password = 'password123';
        
do {
	let fetchedData = try viewContext.fetch(fetchRequest)
	return fetchedData.count > 0
} catch {
	return false
}
content_copyCOPY

This code generates a query that finds the expected data from the coreData's database