How to convert NSIndexpath into NSInteger or simply int?

IphoneCocoa Touch

Iphone Problem Overview


I need to convert a nsindexpath var into NsInteger or simply an int. e.g:

 int rowIndex = [mGoogleBaseTable selectedRow];
 //mGoogleBaseTable is a NSTable type in Macdevelopement..

&&

int rowIndex = [mGoogleBaseTable indexPathForSelectedRow];
//mGoogleBaseTable is a UITableView type in Iphone (iOS)Development.

selectedRow returns NSInteger simply but indexPathForSelectedRow returns a NSIndexPath..

Please help me how can i achieve this.

Iphone Solutions


Solution 1 - Iphone

If

NSIndexPath *p = ... // some indexpath

then

NSInteger row = p.row;
NSInteger section = p.section;

That's all!

Solution 2 - Iphone

Maybe, this is can help you

NSInteger variable = indexPath.row;

Solution 3 - Iphone

In Swift:

    let section: Int = indexPath.section
    let row: Int = indexPath.row

Solution 4 - Iphone

I prefer doing it this way

NSNumber *selRow = [[NSNumber alloc] initWithInteger:indexPath.row];

Solution 5 - Iphone

Simply convert into int by,

NSIndexPath *path = ... // some indexpath

int row = (int)path.row;

Solution 6 - Iphone

In swift :

  1. Associate your collection view to your var :

    @IBOutlet weak var collectionView: UICollectionView!

  2. In prepareForSegue func, you can call :

    var indexPath = collectionView.indexPathsForSelectedItems()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTarunView Question on Stackoverflow
Solution 1 - IphonemvdsView Answer on Stackoverflow
Solution 2 - IphonePS.OHMView Answer on Stackoverflow
Solution 3 - IphoneKing-WizardView Answer on Stackoverflow
Solution 4 - IphonevermaView Answer on Stackoverflow
Solution 5 - IphonePavithaView Answer on Stackoverflow
Solution 6 - IphoneWizaView Answer on Stackoverflow