Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mlecho

macrumors newbie
Original poster
Mar 31, 2004
28
0
Sorry all, i am new to ObjectiveC-> In other programming languages, i like to cast the variable i am working with when in a loop. I have a class (FeedItem) with a property 'description' . I know that my NSMutableArray (menuList) has 15-20 of these FeedItem pushed earlier in my code (i can also see them in the debugger). However, when i prepare to do this loop, i get an error: "error: incompatible types in initialization"

why can't i do this?
Code:
for(int b =0;b<[menuList count];b++)
	{
		FeedItem *fi = menuList[b];
		NSLog(@"----->@%",fi.description);		
	}

again, i am new to objective c, so is it my loop syntax?
 
Assuming that menuList of of type NSArray*, you cannot use the standard bracketed index method to access its elements; you must use the objectAtIndex: method.
For example, say I have an array
Code:
NSArray *foo
with three elements, @"zero", @"one" and @"two" (at their respective indices). Executing the snippet
Code:
NSLog( @"%@", [foo objectAtIndex:0] );
will print "zero" to the console.
 
If you don't need backwards compatibility, the preferred way to loop through an array is:
Code:
for (FeedItem *fi in menuList)
{
    NSLog(@"----->@%",fi.description);		
}
 
thanks guys...both are perfect, and now this new-b can get back on track
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.