CoreData so far is really great 🙂 I really get into it.
Now I’ve got a to-many relationship and want to filter that. I’am stuck here. I have multiple zipcodes for example (44512, 12445, …)
The problem is, if I search for 445 and I use contains = %@ it returns two results (12345, 12445).
I want to get exactly one result, the result should begin with my searchstring. So normally I would use BEGINSWITH = %@. With a to-many relationship I can’t use that. Is there any workaround? 🙂
Thanks a lot for you help, I really appreciate it!
Without seeing your code I can’t completely give an answer. Given your other SO question it looks like your Zips are stored as NSStrings.
So, you can construct an NSPredicate and use
beginswithlike in this example from Apple. Thebeginswithexample is in the Arrays section but you can easily change the predicate for your example and apply it to your NSFetchRequest. If you’ve never done a predicate before, the NSFetchRequest has apredicateproperty. You create the predate, then assign it to the NSFetchRequest’s predicate property and then execute your fetch request.Like I said at the beginning, if you show a code snippet we can be more helpful/specific in our answers.