Simple Question About Fast Enumeration

Discussion in 'Mac Programming' started by Spike099, Apr 14, 2008.

  1. macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #1
    So, I was wondering if interrupting the fast enumeration process would pose any memory issues? Basically, I am wondering if the following code follows proper conventions. Where, as soon as a newsItem that has not beed read is found, the method returns YES.

    Code:
    - (BOOL)hasUnreadNews {
    	for ( NewsItem *newsItem in newsItems) {
    		if ( ![newsItem hasRead] )
    			return YES;
    	}
    	return NO;
    }
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    I don't think there's anything wrong with it. I've been using it in my code for years.

    BTW fast enumeration is really just a do-while loop in disguise :)
     
  3. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
  4. thread starter macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #4
    Yeah it's an NSArray. Alright, the code stays. Thanks guys.

    EDIT. Just looking at that documentation page, Apple even uses break many times.
     

Share This Page