Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I've done a number of searches on this site and google, and perhaps I'm just missing the right keyword combinations to find examples on what I want to do.
I have an NSMutableDictionary that I need filtered then sorted (I know I need to put sorted values in an array, so really it's a 2 part question). Some searches on this forum brought me to this thread many other threads have been dead ends and I hope this wont be one of them.
If you know how to do this, please humor me and at least glance over my current dictionary and maybe you'll toss me a sample keyword that I can use to search more on, or maybe some sudo code that I can work with?
now suppose I want to filter and sort by any key value for Operation_number that is between the range of 0100 to 0199. I looked up the documentation on Predicate from the Apple's Predicate Programming Guide, but I'm afraid that I'm still a little bit lost.
It seems that building a predicate would be the right approach, but it almost seems like I need a degree to figure how to construct a predicate for my dictionary object above. :-|
so I tried crafting this simple example by throwing together some snippets of code off the web but it doesn't seem like it's doable either :(
NSPredicate *predicate = [NSPredicate
predicateWithFormat:@\"(OPERATION_NUMBER >= %@) AND (OPERATION_NUMBER <= %@)\",
@\"0100\", @\"0199\"];
doesn't seem to work, and it's quite possible I'm not doing it right :-|
Thank you for reading my post and if you can help, Thanks!
Convert the values to NSNumber objects before storing them in your dictionary.
I'd have to loop through original dictionary (results from sudzc) to convert it... but if that's the way, I'll loop, however if i'm looping I should just re-create a dictionary then with my filtered contents right?
I do not, in fact I created a settings (standardUserDefaults) to hold filtered values that are needed at each iPad to be configurable for each user. The soap service that I call simply returns the entire payload and I just need small subsets like all row values from 0100 through 0199.
Thanks!! This is what I came up with and it works, note I left the NSLogs in there on purpose, but this will filter my results down to just what is in the filterTo and filterFrom user configured filters. I imagine that there must be a way to default the filterTo to be 9999 if the NSUserDefault is null (because a filter could change while the app is already loaded).
//Defaults int filterFrom = [[[NSUserDefaults standardUserDefaults] valueForKey:@\"FilterFrom\"] intValue] ; int filterTo = [[[NSUserDefaults standardUserDefaults] valueForKey:@\"FilterTo\"] intValue]; if (filterTo == 0) {filterTo = 9999;} NSDictionary *dict; for (dict in [objProdOrder allKeys]) {
Thanks guys for helping me go in the right direction... here is the final part for my sorting, I looked up NSPredicate and other discussed methods even one that involves blocks, this version works for my needs... check it out:
sortedArrayKeys = [unSortedArray sortedArrayUsingComparator: ^(id a, id b) { NSString *first = [[soapDictionary objectForKey:a] objectForKey:@\"ITEM_NUMBER\"] ; NSString *second = [[soapDictionary objectForKey:b] objectForKey:@\"ITEM_NUMBER\"] ; return [first compare:second]; }];
That's it.. the Key value for ITEM_NUMBER is a value in my dictionary from the sudzc calls I made before I got into this mess ;). But now my sortedArrayKeys is tuned to a sorted list which is what my UITableView uses to display it's list... Thanks again for the pointers and helpful nudges :)
Replies
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeDuncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThat's it.. the Key value for ITEM_NUMBER is a value in my dictionary from the sudzc calls I made before I got into this mess ;). But now my sortedArrayKeys is tuned to a sorted list which is what my UITableView uses to display it's list... Thanks again for the pointers and helpful nudges :)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome