So following Apple’s DocInteraction Sample here I put a static NSString to define some preloaded documents. Now I need to load them into an NSArray in the viewDidLoad method. If I put it into a for() statement, it says “expression result unused”, and I know I could solve it by using documents[indexPath.row], but it’s the viewDidLoad method. So how do I forEach a static NSString for loading into the NSArray?
CODE (EDIT):
//Before @implementation
static NSString* documents[] =
{ @"Musette.pdf",
@"Minore.pdf",
@"Cantata.pdf",
@"Finalé.pdf"
};
//In viewDidLoad
if ( _icons == nil )
{
_icons = [[NSMutableArray alloc] init];
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(0, 0, 200.0, 324.0)
cornerRadius: 18.0];
for (NSUInteger i = 1; i <= 4; i++){
UIGraphicsBeginImageContext( CGSizeMake(200.0, 324.0) );
// clear background
[[UIColor clearColor] set];
UIRectFill( CGRectMake(0.0, 0.0, 200.0, 324.0) );
// fill the rounded rectangle
[path fill];
UIImage *image = [UIImage imageNamed:@"ClearImage.png"];
UIGraphicsEndImageContext();
// put the image into our list
[_icons addObject: image];
}
}
[_gridView reloadData];
C-arrays are not supported by the for-each modification of the for statement in Objective-C. So you have 2 choices here:
use ordinary for-statement cycle
for(int idx = 0; idx < KNOWN_DOCUMENTS_COUNT; ++idx) {
…
}
Create a custom subclass of the NSEnumerator and use it… however, I believe, this will be a big overhead for this case