Search Results

Search found 79 results on 4 pages for 'nssortdescriptor'.

Page 4/4 | < Previous Page | 1 2 3 4 

  • NSFetchedResultsController sections localized sorted

    - by Gerd
    How could I use the NSFetchedResultsController with translated sort key and sectionKeyPath? Problem: I have ID in the property "type" in the database like typeA, typeB, typeC,... and not the value directly because it should be localized. In English typeA=Bird, typeB=Cat, typeC=Dog in German it would be Vogel, Katze, Hund. With a NSFetchedResultController with sort key and sectionKeyPath on "type" I receive the order and sections - typeA - typeB - typeC Next I translate for display and everything is fine in English: - Bird - Cat - Dog Now I switch to German and receive a wrong sort order - Vogel - Katze - Hund because it still sorts by typeA, typeB, typeC So I'm looking for a way to localize the sort for the NSFetchedResultsController. I tried the transient property approach, but this doesn't work for the sort key because the sort key need to be in the entity. I have no other idea. But I can't believe that's not possible to use NSFetchedResultsController on a derived attribute required for localization? There are related discussions like http://stackoverflow.com/questions/1384345/using-custom-sections-with-nsfetchedresultscontroller but the difference is that the custom section names and the sort key have probably the same order. Not in my case and this is the main difference. At the end I would need a sort order for the necessary NSSortDescriptor on a derived attribute, I guess. This sort order has also to serve for the sectionKeyPath. Thanks for any hint.

    Read the article

  • Conditionally overriding a system method via categories in Objective-C?

    - by adib
    Hi Is there a way to provide a method implementation (that bears the exact same name of a method defined by the framework) only when the method isn't already defined in the system? For example method [NSSomeClass someMethod:] exists only in Mac OS X 10.6 and if my app runs in 10.5, I will provide that method's definition in a category. But when the app runs in 10.6, I want the OS-provided method to run. Background: I'm creating an app targeted for both 10.5 and 10.6. The problem is that I recently realized that method +[NSSortDescriptor sortDescriptorWithKey:ascending:] only exists in 10.6 and my code is already littered by that method call. I could provide a default implementation for it (since this time it's not too difficult to implement it myself), but I want the "native" one to be called whenever my app runs on 10.6. Furthermore if I encounter similar problems in the future (with more difficult-to-implement-myself methods), I might not be able to get away with providing a one-liner replacement. This question vaguely similar to Override a method via ObjC Category and call the default implementation? but the difference is that I want to provide implementations only when the system doesn't already has one. Thanks.

    Read the article

  • Problem with sorting NSDictionary

    - by Stas Dmitrenko
    Hello. I need to sort a NSDictionary of dictionaries. It looks like: {//dictionary RU = "110.1"; //key and value SG = "150.2"; //key and value US = "50.3"; //key and value } Result need to be like: {//dictionary SG = "150.2"; //key and value RU = "110.1"; //key and value US = "50.3"; //key and value } I am trying this: @implementation NSMutableDictionary (sorting) -(NSMutableDictionary*)sortDictionary { NSArray *allKeys = [self allKeys]; NSMutableArray *allValues = [NSMutableArray array]; NSMutableArray *sortValues= [NSMutableArray array]; NSMutableArray *sortKeys= [NSMutableArray array]; for(int i=0;i<[[self allValues] count];i++) { [allValues addObject:[NSNumber numberWithFloat:[[[self allValues] objectAtIndex:i] floatValue]]]; } [sortValues addObjectsFromArray:allValues]; [sortKeys addObjectsFromArray:[self allKeys]]; [sortValues sortUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"floatValue" ascending:NO] autorelease]]]; for(int i=0;i<[sortValues count];i++) { [sortKeys replaceObjectAtIndex:i withObject:[allKeys objectAtIndex:[allValues indexOfObject:[sortValues objectAtIndex:i]]]]; [allValues replaceObjectAtIndex:[allValues indexOfObject:[sortValues objectAtIndex:i]] withObject:[NSNull null]]; } NSLog(@"%@", sortKeys); NSLog(@"%@", sortValues); NSLog(@"%@", [NSMutableDictionary dictionaryWithObjects:sortValues forKeys:sortKeys]); return [NSMutableDictionary dictionaryWithObjects:sortValues forKeys:sortKeys]; } @end This is the result of NSLog: 1) { SG, RU, US } 2) { 150.2, 110.1, 50.3 } 3) { RU = "110.1"; SG = "150.2"; US = "50.3"; } Why is this happening? Can you help me with this problem?

    Read the article

  • Limit Annotation number in Mapkit

    - by teddafan
    Hi all, I want to stop my app from loading more annotations after they are all added ( they are added by the user one by one). How would you do that? the following code is what i think is important (void) loadAndSortPOIs { [poiArray release]; nextPoiIndex = 0; NSString *poiPath = [[NSBundle mainBundle] pathForResource:@"pois" ofType:@"plist"]; poiArray = [[NSMutableArray alloc] initWithContentsOfFile:poiPath]; CLLocation *homeLocation = [[CLLocation alloc] initWithLatitude:homeCoordinate.latitude longitude:homeCoordinate.longitude]; for (int i = 0; i < [poiArray count]; i++) { NSDictionary *dict = (NSDictionary*) [poiArray objectAtIndex: i]; CLLocationDegrees storeLatitude = [[dict objectForKey:@"workingCoordinate.latitude"] doubleValue]; CLLocationDegrees storeLongitude = [[dict objectForKey:@"workingCoordinate.longitude"] doubleValue]; CLLocation *storeLocation = [[CLLocation alloc] initWithLatitude:storeLatitude longitude:storeLongitude]; CLLocationDistance distanceFromHome = [storeLocation getDistanceFrom: homeLocation]; NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc] initWithDictionary:dict]; [mutableDict setValue:[NSNumber numberWithDouble:distanceFromHome] forKey:@"distanceFromHome"]; [poiArray replaceObjectAtIndex:i withObject:mutableDict]; [mutableDict release]; } [homeLocation release]; // now sort by distanceFromHome NSArray *sortDescriptors = [NSArray arrayWithObject: [[NSSortDescriptor alloc] initWithKey: @"distanceFromHome" ascending: YES]]; [poiArray sortUsingDescriptors:sortDescriptors]; NSLog (@"poiArray: %@", poiArray); } Thank you for your help. Best regards,

    Read the article

< Previous Page | 1 2 3 4