Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 953
Anton Avatar asked Feb 27 '13 19:02

Anton


People also ask

Is iOS file system case sensitive?

No. MacOS is not a case sensitive file system by default. So you can't have two files named File.

What is a case-insensitive filesystem?

Two files that differ only by case is not allowed. Case-insensitive: This is the file-system used by very old Windows versions and is rarely encountered "in the wild". Two files that differ only by case is not allowed and the case used to create a file is not preserved.

How do I know if my Mac is case sensitive?

Open Disk Utility, located in the /Applications/Utilities directory. Select Macintosh HD. In the bottom-left corner, check if Case-sensitive is listed.


1 Answers

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.

like image 182
Rob Napier Avatar answered Nov 15 '22 06:11

Rob Napier