在xcode中,我有许多名为.plist的文件:ImageData1.plist,ImageData2.plist ......等
如何获取以“ImageData”名称开头的.plist文件的数量?
答案 0 :(得分:1)
快速而肮脏的解决方案:
int count = 0;
for (int i = 1; i<100; i++) {
NSString * format = @"ImageData%u";
NSString * file = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:format,i] ofType:@"plist"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:file];
if (fileExists) {
count ++;
} else {
break;
}
}
NSLog(@"-----> Number of files = %u", count);
如果序列中没有丢失的文件,则此方法有效(例如ImageData1.plist,ImageData2.plist,ImageData4.plist ...)