开发者

counting the number of .plist files in xcode

开发者 https://www.devze.com 2023-01-18 05:06 出处:网络
In xcode, I have many .plist开发者_如何学编程 files called : ImageData1.plist, ImageData2.plist ... etc

In xcode, I have many .plist开发者_如何学编程 files called : ImageData1.plist, ImageData2.plist ... etc

how can I get the number of .plist files which start with the name "ImageData" ?


A quick and dirty solution:

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);

This method works if you don't have missing files in the sequence (e.g. ImageData1.plist, ImageData2.plist, ImageData4.plist...)

0

精彩评论

暂无评论...
验证码 换一张
取 消