NSFileManager Attributesforitem not working and returns null

I am currently working on an iOS application that requires NSFileManager , but when I use the attributesOfItemAtPath: method, it returns null. This also fails for NSData and the dataWithContentsOfFile: method. I do not understand why this is happening. The URL I use looks something like this: file://localhost/private/var/mobile/Applications/597DE145-33D7-4F92-AE95-029D5CF15291/tmp/Kv7DWqtRWH7WnN47HdDW . I suspect this might be due to the url, but I'm not sure.

+4
source share
1 answer

You need to convert the NSURL to a path for use with any of the NSFileManager methods that take a string. Do this by calling the path method at the URL.

 NSURL *someURL = ... // some file URL NSString *path = [someURL path]; // convert the file:// URL to a file path NSDictionary *info = [[NSFileManager defaultManager] attributesOfItemAtPath:path]; 
+13
source

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


All Articles