---
title: "How to get class object index in NSMutableArray in Xcode?"  
description: "How to get class object index in NSMutableArray in Xcode?"  
author: "Anonymous User"  
published: 2016-01-23  
updated: 2016-01-23  
canonical: https://www.mindstick.com/forum/33915/how-to-get-class-object-index-in-nsmutablearray-in-xcode  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# How to get class object index in NSMutableArray in Xcode?

I have two [controllers](https://www.mindstick.com/forum/155773/how-asynchronous-controllers-work-in-asp-dot-net-mvc) in our [iPhone application](https://www.mindstick.com/forum/23139/can-i-embed-a-custom-font-in-an-iphone-application). In one [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) I have create a **ImageCollection** [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) and an **NSMutableArray** **imgArray**. after that I have [stored](https://www.mindstick.com/forum/157561/what-is-the-stored-procedure-create-a-procedure-to-find-the-record-by-stu_id-from-the-student-table) ImageCollection [objects](https://www.mindstick.com/forum/145447/what-are-objects) into the imgArray. Now, I want to get the specific [index](https://www.mindstick.com/blog/198/index-in-sql-server) of ImageCollection object which is stored in the imgArray.\
Can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) how can I find the index of any specific object. Please provide me some [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) if possible as hint for me.\
Thank You.

## Replies

### Reply by Tarun Kumar

To get the index of object from the mutable array. For that- first of all import the FirstViewController (where you create ImageCollection class and array) in the SecondViewController and under the @interface create a property of NSIndexPath. like this:

```
@interface SecondViewController:UIViewController@property NSIndexPath *indexPathOfImage;...@end
```

Now, go to the FirstViewController's implementation file import the SecondViewController. now, under the didSelectItemAtIndexPath: method of CollectionView create a reference of second view controller using storyboard like this:

```
SecondViewController *secondController = [self.storyborad instantiateViewControllerWithIdentifier:@"SecondViewController"];
```

now, when ever any collection view cell will be clicked, collection view method didSelectItemAtIndexPath: will be called which has the indexPath. Now we will assign it in the second view controller property indexPathOfImage, like this:

```
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{  ...  SecondViewController *secondController = [self.storyborad instantiateViewControllerWithIdentifier:@"SecondViewController"];  secondController.indexPathOfImage = indexPath;  ...}
```

Now, we can use it in the second view controller to get the index from imgArray, like this:

```
SecondViewController *secondViewController * [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];ImageCollection *imgCollection = [secondViewController.imgArray objectAtIndex:_indexPathOfImage];
```

that's it. I hope it will be helpful for you.


---

Original Source: https://www.mindstick.com/forum/33915/how-to-get-class-object-index-in-nsmutablearray-in-xcode

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
