0
votes

I am storing the parsed xml values as Global data in Mutable Array some thing like this...

.h file

@interface GlobalData : NSObject {

NSMutableArray *array;

}

@property(nonatomic,retain) NSMutableArray *array;

  • (id)sharedData;

In .m file

static GlobalData *sharedGlobalData = nil;

@implementation GlobalData

@synthesize array;

+(id)sharedData{

@synchronized(self) {
    if(sharedGlobalData == nil)
    {
        sharedGlobalData=[[GlobalData alloc] init];
        sharedGlobalData.boats=[[NSMutableArray alloc] init];

    }
}
return sharedGlobalData;

}

  • (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if(sharedGlobalData == nil) { sharedGlobalData = [super allocWithZone:zone]; return sharedGlobalData; } } return nil; }

I am passing the value of array to a Table view and displaying it as a table. Now i want to sort this array alphbetically from A-Z and pass it to table view.How can i do this???... Plz help

1

1 Answers

0
votes

Got it by using NSSortDescriptor....

something like this,

    NSSortDescriptor *alphaDesc = [[NSSortDescriptor alloc] initWithKey:@"boatName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
    [[data boats] sortUsingDescriptors:[NSMutableArray arrayWithObjects:alphaDesc, nil]];