SHTwoDimensionalArray : A simple and easy to use two dimensional array for iOS applications.

Standard

Ever felt the need to use a two dimensional array in you iOS project? Well, I have. So here is what I had done:

  • Created a NSObject subclass.
  • Taken two private NSMutableArray instances, one for row and one for column.
  • Created a nested for loop to traverse those arrays, and fill them with NSNull objects.
  • Created a method to insert value/object on the [row][column] index.

So this is fairly easy and straightforward. But wouldn’t it be nicer if you didn’t have to do all these steps and figure out how to write those monotonous codes all by yourself?

My good friend, I have good news for you! I have created a simple CocoaPod to minimize your task!

To install it, simply add the following line to your Podfile:

pod 'SHTwoDimensionalArray'

and run

pod install

command!

To use this, try the following code snippet:

#import "SHTwoDimensionalArray.h"

SHTwoDimensionalArray *twoDArray = [SHTwoDimensionalArray arrayWithRows:2 andColumns:2];
[twoDArray setObject:@"Foo" inRow:0 column:0];
...

NSString *foo = [twoDArray objectInRow:0 column:0];

I hope you find it helpful and it’s under MIT license. Feel free to fork, modify and contribute!

Cheers!

One thought on “SHTwoDimensionalArray : A simple and easy to use two dimensional array for iOS applications.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s