0

Am not well familiar in Coredata storage. I want to save multiple data for a single person and retrieve the data of a selected person. Like wise i have store values in coredata table like below,

ID     Name    Date                 Report                  Status
1      Gopi    31 June 01.90pm      ABCD                    Y
2      Robot   27 June 2 am         hdfsdfk                 N
1      Gopi    31 June 02.00pm      fsdjk                   N
2      Robot   29 June 3am          eyrwruo                 Y
1      Gopi    1 July 3pm           rweyskd                 Y
1      Gopi    2 July 2pm           ABCD                    N
2      Robot   1 July 2.40pm        eirwierundfs            Y
3      John    2 July 10am          fewyrhhskd              Y
3      John    3 July 11am          sdkfksjfnvmnfks         N

In my first view controller i want to show the details like this in tableview,

Gopi            2 July 2pm     >
ABCD            Y 
Robot           1 July 2.40pm  >
eirwierundfs    Y
John            3 July 11am    >
sdkfksjfnvmnfks Y

When the user selects Gopi, It will navigate to another view controller with table view and they can view all records of named Gopi. And also i want to delete the selected user details from the entitiy. Can anyone please help me to get a unique user details from Coredata?

I have stored the values in coredata entity and retrieved all the rows from the entity. But, now am struggling to get a unique values of selected person data from the entity. Could you please help me? Thanks in advance.

Gopinath
  • 5,392
  • 21
  • 64
  • 97

1 Answers1

3

While fetching record from core data add these two lines

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Name==%@",str];
 //  Give your attribute name instead of "name"
 //  In str give the name "gopi" (for your case)  or whatever you want    

[fetchRequest setPredicate:predicate];
//set predicate to your fetch request

Then execute fetch request

Dinesh Kaushik
  • 2,917
  • 2
  • 23
  • 36
  • Mr.Dinesh thanks a lot for your answer. I will try it now itself. It is possible to delete selected user data from Coredata entity. could you please help me. Thanks. – Gopinath Jul 03 '12 at 06:48
  • @Gopinath Have you actually read the Apple documentation regarding CoreData? Perhaps if you read it, you would be able to answer your own questions on this... https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdCreateMOs.html – Nick Bull Jul 03 '12 at 08:22
  • Yes you can delete the selected user data. Fetch the object to be deleted using predicate and then delete that object – Dinesh Kaushik Jul 03 '12 at 08:28
  • @NickBull Thanks for your help. Am started to study about the Coredata. But, now am in rush to complete it that's why i posted this question and needed help from you all. Thanks. – Gopinath Jul 03 '12 at 08:45
  • @DineshKaushik Thank you for your post. I will try it and let you know. Thanks. – Gopinath Jul 03 '12 at 08:45