How to get unique values retrieve from Coredata iphone app?

我与影子孤独终老i 提交于 2019-12-08 11:10:44

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/11305590/how-to-get-unique-values-retrieve-from-coredata-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!