How to escape an NSString to use in NSURL?

ios, nsstring, objective-c

Solution

You need to separate the two string construction calls

NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];

Problem

Got this code so far for my send button: ``` NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone+App&message=%@", messageBox.text stringByAddingPercentEscapesUsingEncoding : NSUFT8StringEncoding]; NSURL *add = [NSURL URLWithString:urlString]; ``` However I do get the error "Expected ':'

Original source