CoreData fetch entities with same values - iphone

I have a CoreData entity called Item with two values (well, two values relevant to this question).
Item
---------------
id - NSString
name - NSString
Every item has a unique ID and SHOULD have a unique name.
(BTW, the id is not used for CoreData it is used for communicating with the server).
There are a couple of items which appear to have duplicate names and I'm trying to find a query that returns all items that have an item in the table with a duplicate name.
Is this possible?
If so, can someone provide an NSPredicate (or method) to do this.

I do not think that it is possible to fetch exactly the items with duplicate names with a Core Data fetch request. (I think there was a similar question some time ago here on SO, but I cannot find it right now.)
You could fetch all items sorted by the name attribute. Then the duplicates can be found with a single loop over the result array.

Related

Swift: Core Data - Resolving a logic issue with object creation

So, my Swift app allows a user to choose sports teams to see historic match information for. Currently, a user selects team(s) and the JSON data file of historic matches is scanned.
If a historic match includes a name of a selected team, the details of the match are stored in a Core Data entity, which is fed into my main Table View.
However, this presents an issue I can't get my head around solving.
If a user selects team A and B, and the database contains a match where team A and B played EACH OTHER, two objects for the match details are created, and as such, Table View cell is created twice, once for team A being found in the instance of the match, and again for team B.
Is there an easy and efficient way to trim any duplicates caused in this way? I don't know whether to handle this at the object creation time, or just to find a way of removing any duplicated cells from my Table View.
Thanks so much.
I think you should redesign your setup. Have all the records to be searched stored in Core Data.
If you have a hardcoded JSON file - import it on first start. If you have retrieved JSON - insert / update the elements that are new / changed in your Core Data object graph.
You would have a Match or Game entity and it would be retrieved only once. The fetch predicate would be something like
NSPredicate(format: "homeTeam = %# || guestTeam = %#", selectedTeam, selectedTeam)

Filemaker Value List Troubles - Missing Items

I am relatively new to Filemaker programming, but I have come across what I thought was a bug, which I have been tearing my hair out trying to squash, only to find it is more a "feature" than a bug. I have a field set as the key for lookups in a ms sql database which I have created a relationship with. I have it set as a drop down, and it is showing 2 fields (last name and first name). Unfortunately, it only shows 1 person per last name in the sorted list (example, there are 5 people with the last name "Bennett" but only 1 shows). After driving myself nuts trying to find the error, I found the following in the filemaker troubleshooting section:
"
If the value list is defined to display information from two fields, items will not be duplicated for the field on which the value list is sorted. For example, if the value list displays information from the Company field and the Name field, and if the values are sorted by the Company field, only one person from each company will appear in the value list."
As I read it, I can't do what I need to do with a value list (display EVERY last name from the sql file) so what other options do I have? I have experimented with creating a portal which DOES show a list of ALL the last names and first names, but I don't know/understand enough to know what logic/functionality I need so if I click one of the people in the portal list it will do the same thing as if I clicked it in a dropdown value list, which is to then do the lookups and populate the rest of the fields in this database from the information in the record in the sql database. Any and all help would be greatly appreciated, and I appreciate any help any of you can offer. Thank you!
There might be some things that cause this;
You cannot create a link based on a calculation that needs to be calculated each time (Filemaker does not know what to do with this, logical in a way)
Based on what you do I would personally link the two tables based on an lets say company ID instead of a name, as a one to many join. This will definitely eliminate the 'feature' filemaker has of showing unique names only in the joined table. On database level I would join on ID, on Value list I would select the ID as first field and the (calculated) name as second field, than showing only the second field (option in the value list definition popup) for your selection list.
Hope this helps.

Searching data in the table that have database object

I have a client data base that has many values related to it.
Client name
Client address
Client code
Client dob
I need to show the client's name in table and allow user to search the client. I add the records to an array and show in a table.
for (Clientes *info in fetchedObjects10)
{
NSString* dict = info.name;
[dataArray addObject:dict];
}
I also create a filtered array for search. But when I search, how I would know which client is selected? How will get other info of that client?
For example, if I search for A in table then filter array is having only 2 elements. If I select the first item, how do I get that item's additional info like address, code, and dob?
As Per i understand your query. you can do it by two ways:-
1) pull all the database fields in the different array (client,client address,client code,client dob ).
search for the client array. The index it was successful pull the other fields from the array.
2) whenever you find the success in searching for the client. Again search the database with the query
sélect cient_address,client_code,client_dob from tablename where client_id=client;
Use the second method if you lot of data. but at the same time client should be the primary key for it.
Reply if there is some more need or your requirement is different.

Core Data Fetched Results Order

I"m working with a core data model of Employees. Each employee is assigned a building and a department. I am returning everyone in building 1 with the predicate, building == 1 and using the sectionNameKeyPath parameter to break the result set down into groups by department.
Right now I have a sort descriptor ordering the departments alphabetically, but is there a way to ignore sorting them alphabetically and organize them in my own way, like engineers first, security second so on and so forth? I'm still getting used to the terminology and there's probably something I'm overlooking.
Thanks,
Note that the sortDescriptors property of the fetched results controller is an array, so you can set multiple sort descriptors which will be used in the order you specify them (e.g. first by department.name, then by lastName, then by firstName).

How to iterate through an NSArray of objects and create a new NSArray containing a subset of the original?

I am working on a basic iPhone app that pulls restaurant objects from a SQLite table, and displays them for the user in a table. My app is navigation based. I have no problems pulling the data from the SQLite database, and then sorting them. That I am able to do no problem. Each restaurant object has various properties, like "name", "address", "category" (i.e. the type of restaurant like greek, italian), and others. Now, after retrieving the records from the database, I am able to successfully put them into an NSMutableArray, and then sort them into an NSArray.
My question is, using this NSArray (or the original NSMutableArray), I'd like to create another array, with the first index containing "All", and then each remaining index contain the unique name of the category of restaurant from the original list, sorted in alphabetical order, and then present this as a table to the user on the next screen. From this table, if the user selects "All", the user will be taken to another screen displaying another table where they can see all the restaurants, regardless of genre.
If however, the user selects a particular category from the available list, the user will be taken to a screen that displays a table composed of only those restaurants of that type (e.g. only Italian restaurants, only Chinese restaurants, only Thai restaurants). How would I go about doing this? Any ideas or suggestions?
One possible algorithm outline:
Iterate over your NSMutableArray (e.g. for(item in array)) inserting the category property of each item into an NSMutableSet (or an NSCountedSet if you'd also like the number of times each category occurs)
Use the NSSet sortedArrayUsingDescriptors: method to obtain a sorted array of the categories.
Add the All entry in whatever way suits