Substituting for-each for NSMutableArray

For all those who learn Objective C with GNUstep…

Mostly you will learn using For-Each statement , for manipulating NSMutableArray.
But with GNUstep, it is not possible.
The for each statement looks like this,

	for(NSObject *st in myMutableArrayObject) {
			NSLog(@"%@",[st myMethodDefined]);
	}

Here is how we can do it without For-Each statement,

	for(i=0; i< [myMutableArrayObject count]; i++) {
		NSLog(@"%@",[[myMutableArrayObject objectAtIndex: i] myMethodDefined]);
	}

Here, we are using a method predefined called count which returns the number of objects in the MutableArray Object
and then another method objectAtIndex which iterates the objects at the interval from 0 to (count – 1).

Advertisements

One thought on “Substituting for-each for NSMutableArray

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s