How to convert NSIndexPath to NSString-iOS

Namratha picture Namratha · May 12, 2011 · Viewed 11.5k times · Source

I want to convert NSIndexPath to NSString. How would I do it? I have to use this:

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)sourcePath 
{
    [client deletePath:@"/objc/boston_copy.jpg"];
}

inside commitEditingStyle method where I only get NSIndexPath as input.

- (void)tableView:(UITableView *)aTableView 
        commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
        forRowAtIndexPath :(NSIndexPath *)indexPath 
{                  
    [self.itemArray  removeObjectAtIndex:indexPath.row];          
    [aTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                      withRowAnimation:YES];    
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]
                  withRowAnimation:UITableViewRowAnimationFade];   
}  

Answer

Eiko picture Eiko · May 12, 2011

I made this a category on NSIndexPath at one point in time:

@interface NSIndexPath (StringForCollection)

-(NSString *)stringForCollection;

@end

@implementation NSIndexPath (StringForCollection)

-(NSString *)stringForCollection
{
    return [NSString stringWithFormat:@"%d-%d",self.section,self.row];
}

@end