Search code examples
objective-cuiimagefile-type

How can I check if a file is an image file without checking the path extension?


I need to differentiate between text file and image file without taking a look their path extension.

I would like to check if the file is actually the image or not. After searching, there is the way to check the mimetype from path extension, however, I would like the solution to verify the file's content itself.


Solution

  • UIImage *image = [UIImage imageNamed:@"SomeFile.xyz"];
    if (image == nil) {
        NSLog(@"This is probably text file");
    }
    

    If image is nil means the file may be text or another type of file.