Search code examples
iosobjective-cfile-iocase-sensitivecase-insensitive

How can I read, write and check case-insensitive filenames in iOS?


I understand that iOS filenames are case-sensitive while OSX filenames can be case-insensitive. Apple's iCloud design guide says:

"To make your document file format cross-platform compatible, you must read and write files in a case-insensitive manner." (from http://developer.apple.com/library/ios/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForDocumentsIniCloud.html)

I want to make my app's file management case-insensitive in iOS. What is the correct way to deal with reading and writing files, and also checking whether files exist (using [NSFileManager fileExistsAtPath:]) in iOS in a case-insensitive way, both in iCloud and on the local filesystem?


Solution

  • There is no specific thing that will make iOS case-insensitive. It is what it is. What they are telling you is that you must not rely on case sensitivity (don't create files that differ only by case), and that you shouldn't be sloppy with your use of case (don't create "readme" and then read "Readme").

    If you accept arbitrary filenames from the user on iOS, and then plan to send those to iCloud, then you will need to query for all the files that exist on iCloud and verify that there is no case-insensitive conflict (using [NSString caseInsensitiveCompare:]). This shouldn't come up a lot, though, as long as you're using iCloud exclusively.