Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get sorted NSArray of date for NSDictionary.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 394
    Comment on it

    With the help of following code you can sort the given dictionary containing key as Date.

    @implementation NSMutableDictionary (SortingNSMutableDictionary)
    
    -(NSArray *)getAllSortedKeys{
        NSMutableArray *array = [NSMutableArray arrayWithArray:[self allKeys]];
            [array sortUsingComparator: (NSComparator)^(NSString *a, NSString *b)
             {
    
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
             [dateFormatter setDateFormat:@"MMMM yyyy"];
             NSDate *date1 = [dateFormatter dateFromString:a];
             NSDate *date2 = [dateFormatter dateFromString:b];
             return [date2 compare:date1];
    
         }
         ];
    
    
    
        return array;
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: