What are the special considerations that need to be taken into account when converting a user input string into a valid file name on iOS? Are there any methods available that can help? I couldn't find anything obvious on NSString
or NSFileManager
.
The context is allowing users to save searches within the app. Behind the scenes, these names are converted into the names of Core Data persistent stores. The actual file names are never exposed to the user.
Thanks in advance.
The primary concern should be the user experience: The user can type anything to identify the file. When coming back to the data she would expect to see exactly the same string she typed in.
The best way to handle this information is to store the actual input somewhere else and use a mapping to get to the actual file.
You could just use a dictionary saved in a plist file. The dictionary would contain the user input as key and a UUID as value. The file is then saved using the UUID as a file name. This way you are sure that the filename is always valid and the user can type whatever she wants without fear for invalid filenames.
An advantage over just stripping invalid characters is that the user can use for instance "/" and "//" as valid identifiers if she feels like it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With