How to convert NSIndexPath to NSString-iOS

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

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

inside the 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]; } 
+4
source share
4 answers

I made this 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 
+5
source

I made this extension to help with debugging:

 @interface NSIndexPath (DBExtensions) - (NSString *)indexPathString; @end @implementation NSIndexPath (DBExtensions) - (NSString *)indexPathString; { NSMutableString *indexString = [NSMutableString stringWithFormat:@"%lu",[self indexAtPosition:0]]; for (int i = 1; i < [self length]; i++){ [indexString appendString:[NSString stringWithFormat:@".%lu", [self indexAtPosition:i]]]; } return indexString; } @end 
+3
source

You cannot convert NSIndexPath to a string - NSIndexPath is just an array of integers. Assuming that β€œconvert” means that you want to access data associated with a specific path, you need to return to the source of that data.

If you created a table from an array of objects, which is usually the case, you just look at the object in the array index equal to the first element of indexPath. If the table is partitioned, you need to look at how the data for partitioning was obtained - this probably applies to sorting objects based on some property of the object.

There is no conversion, just looking at the data source in the same way as when creating the table.

+1
source
 extension NSIndexPath { var prettyString: String { var strings = [String]() for position in 0..<length { strings.append(String(indexAtPosition(position))) } return strings.joinWithSeparator("_") } } 
0
source

All Articles