我有一个由所有对象组成的数组。我不知道哪个索引包含哪个对象。当我使用这个数组时,我只使用索引号。如何在该索引处查找对象的名称?
NSString *extension = @"png";
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSMutableArray *pngFiles = [NSMutableArray arrayWithCapacity: [contents count]];
NSString *filename;
for (filename in contents)
{
if ([[filename pathExtension] isEqualToString:extension])
{
[pngFiles addObject:[UIImage imageWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:filename]]];
}
}