nsfetchrequest

Check data exist before saving in coredata -Swift

核能气质少年 提交于 2019-12-02 09:26:15
While saving the data am checking whether the data is already exist or not in the entity. Problem here is the above method is not working as expected, when I run the app for very first time it's showing data is already exist. Please check the below code and shed some light. Thanks. func someEntityExists(id: String, entityName: String, type : String, fieldName : String) -> Bool { let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: entityName) if type == "String"{ fetchRequest.predicate = NSPredicate(format: "\(fieldName) == %@", id) }else{ fetchRequest.predicate = NSPredicate(format:

How can i save JSON objects to Core Data?

女生的网名这么多〃 提交于 2019-12-01 21:58:55
问题 I'm a nwebie in Core Data, i have designed a navigation based application and some of the data i use are created on run time(come from a URL via JSON). I took a few tutorials an searched for almost a day but haven't still realized how to save the incoming JSON data to the Entity (or event?) in my Core Data model. I fetch the data in the DetailViewController class and i need to save this data to Core Data(I have prepared an Entity with 7 properties). Can anyone please help?(If you know a good

How can i save JSON objects to Core Data?

左心房为你撑大大i 提交于 2019-12-01 21:57:21
I'm a nwebie in Core Data, i have designed a navigation based application and some of the data i use are created on run time(come from a URL via JSON). I took a few tutorials an searched for almost a day but haven't still realized how to save the incoming JSON data to the Entity (or event?) in my Core Data model. I fetch the data in the DetailViewController class and i need to save this data to Core Data(I have prepared an Entity with 7 properties). Can anyone please help?(If you know a good tutorial or sample code i will be pleased) EDIT This may be a little specific but i really have trouble

Show distinct results in fetch request, group by an attribute and calculate the total for that attribute

一世执手 提交于 2019-12-01 20:41:25
Scenario: I have an expense tracking iOS Application and I have a view controller called "DashBoardViewController" (table view controller - with FRC) which would basically categorize my expenses/incomes for a given week, a month, or year and display it as the section header title for example : (Oct 1- Oct 7, 2012) and it shows expenses/incomes ROWS and related stuff according to that particular week or month or year. My Question: What I want to accomplish is : Suppose I save 3 new expenses with SAME category named "Auto" on three different dates(11 nov, 14 nov, 16 nov, 2012 respectively). In

NSSortdescriptor ineffective on fetch result from NSManagedContext

跟風遠走 提交于 2019-12-01 18:47:56
I'm trying to sort my NSFetchRequest result using a NSSortdescriptor using a key pointing to a NSDate value. My fetch results come out totally random for no clear reason. The NSManagedObjectContext I'm using is updated with a save from a nested child context created on a subclass of NSOperation. I know all this is done successfully because I can get all the data needed from the parent (main) context. Fetching from it just wont sort on date! Strange thing is; predicates for selecting the entities (called "Tweet") between two dates works just fine! Here's some code to illustrate my problem:

NSPredicate on nested object / NSSet to filter the result during NSFetchRequest

一个人想着一个人 提交于 2019-12-01 14:17:43
I want a simple predicate that returns me all the groups which have mode = 0 and the mode of the enrollments in the group = 0 To be precise i need a predicate to access the nested object properties. Somehow a predicate like: [NSPredicate predicateWithFormat:@"mode = 0 AND enrollments.Enrollment.mode = 0"] the above predicate is wrong and obviously doesn't work. EDITED: I have given a go to the following predicate too but been unsuccessful. [NSPredicate predicateWithFormat:@"mode = 0 AND ALL ( SUBQUERY(enrollments,$varEnrollment,$varEnrollment.mode = 0))"] I need result which contains all

NSPredicate on nested object / NSSet to filter the result during NSFetchRequest

谁说胖子不能爱 提交于 2019-12-01 12:48:07
问题 I want a simple predicate that returns me all the groups which have mode = 0 and the mode of the enrollments in the group = 0 To be precise i need a predicate to access the nested object properties. Somehow a predicate like: [NSPredicate predicateWithFormat:@"mode = 0 AND enrollments.Enrollment.mode = 0"] the above predicate is wrong and obviously doesn't work. EDITED: I have given a go to the following predicate too but been unsuccessful. [NSPredicate predicateWithFormat:@"mode = 0 AND ALL (

Swift 3. NSFetchRequest propertiesToFetch

给你一囗甜甜゛ 提交于 2019-12-01 11:26:33
In Swift 3 when we use NSFetchRequest , we have to specify NSFetchRequestResult . But how to get an array of properties values? If I use something like this let fetchRequest = NSFetchRequest<MyClass>(entityName: "MyClass") fetchRequest.propertiesToFetch = ["myAttributeName"] an exception fires when I try to execute fetch request. error: -executeRequest: encountered exception = The database appears corrupt. If I remove a line with propertiesToFetch I don't get any errors, but I get an array of objects, not properties. I forgot to set resultType for NSFetchRequest. let fetchRequest =

NSPredicate traversing relationship (StackMob)

放肆的年华 提交于 2019-12-01 08:15:26
I have been scouring Apple's Predicate Programming Guide and SO as well, trying to determine the correct way to write a predicate for a certain fetch request. It seems like the way I am attempting to use dot notation to traverse a relationship is not being respected by the request. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"project.user == %@", self.user]; [fetchRequest setPredicate:predicate]; User, Project, and Task are all core data

NSPredicate traversing relationship (StackMob)

百般思念 提交于 2019-12-01 05:56:28
问题 I have been scouring Apple's Predicate Programming Guide and SO as well, trying to determine the correct way to write a predicate for a certain fetch request. It seems like the way I am attempting to use dot notation to traverse a relationship is not being respected by the request. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"project.user ==