Number of images

Hi guys I was working on Application, and I'm trying to count the number of images in the resource folder and display no.of images in Simulator Can any of you work hard? give me the code

-3
source share
1 answer

If you want to do this, you will need to use the NSFileManager to view the contents of [[NSBundle mainBundle] bundlePath] (the path of your application package) to find all files with the correct extension.

The best question is: why do you want to do this?

Edit: in order, if you insist, you will need to do something like this:

 NSEnumerator *iter = [[NSFileManager defaultManager] directoryEnumeratorAtPath:[[NSBundle mainBundle] bundlePath]]; int count = 0; // number of images for (NSString *path in iter) { // iterate through all files in the bundle if ([[path pathExtension] isEqualToString:@"png"]) { // test if the extension is "png" count++; // increment the number of images UIImage *img = [UIImage imageWithContentsOfFile:path]; // do other things with the image } } 
+1
source

Source: https://habr.com/ru/post/896851/


All Articles