I need to create String "\b" . But when I try, Xcode throws a compile-time error: Invalid escape sequence in literal. I do not understand why, however, "\r" works fine. If I put "\\b" , then what is actually stored in String is not what I need - I only need one backslash. For me, this seems like Swift weirdness because it works great in Objective-C.
let str = "\b" //Invalid escape sequence in literal NSString *str = @"\b"; //works great
I need to generate this line because "\b" is the only way to detect when the user clicked "delete" when using UIKeyCommand :
let command = UIKeyCommand(input: "\b", modifierFlags: nil, action: "didHitDelete:")
How can I get around this problem?
EDIT: it really doesnβt want to generate a line that is only "\b" , this will not work - it remains the original value:
var delKey = "\rb" delKey = delKey.stringByReplacingOccurrencesOfString("r", withString: "", options: .LiteralSearch, range: nil)
source share