I\'m using very tricky fighting methods :) to make a string like Fi?le*/ Name
safe for using as a file name like File_Name
.
I\'m sure there is a cocoa
I iterated on johnboiles's answer, converting to Swift, and writing it as an extension:
extension String {
var stringForFilePath: String {
// characterSet contains all illegal characters on OS X and Windows
let characterSet = NSCharacterSet(charactersInString: "\"\\/?<>:*|")
// replace "-" with character of choice
return componentsSeparatedByCharactersInSet(characterSet).joinWithSeparator("-")
}
}
Illegal character set referenced from here.