Search code examples
objective-cxcodetokencode-snippets

How to prevent xcode treating <# #> as a code snippet placeholder


I want to include <# #> in a literal string in an Objective C program. However, Xcode automatically replaces the string thinking it should be a placeholder as used in code snippets.

e.g.

NSString *pattern = @"<#foo#>"

Try putting this into Xcode and it redisplays as a placeholder for foo.

In the actual program the string is an RE like this <#(.*)#> and surprisingly, the code actually works as intended - the problem only manifests itself in the display in Xcode. The real problem is that this creates a fragile situation, it is far too easy to cause the text to be replaced accidentally when in the editor.

As a workaround I can construct the string from it's parts

NSString *p1 = @"<#(.*)";
NSString *p2 = @"#>";
NSString *pattern = [NSString stringWithFormat:@"%@%@",p1,p2];

but that is not very satisfactory.

Does anyone know a better way to override this behaviour in Xcode?


Solution

  • You can avoid the bad behavior by taking advantage of string concatenation, e.g.

    NSString *str = @"<" "#foo#" ">";