iOS 9.2.1, 7.2.1, Xcode ARC activado
Siempre se puede añadir el '%' por sí mismo, sin ningún otro especificadores de formato en la cadena que está anexando, al igual que ...
int test = 10;
NSString *stringTest = [NSString stringWithFormat:@"%d", test];
stringTest = [stringTest stringByAppendingString:@"%"];
NSLog(@"%@", stringTest);
para iOS7.0 +
para ampliar la respuesta a otros personajes que podrían causar que entren en conflicto puede optar por utilizar:
- (NSString *)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet *)allowedCharacters
Escrito cabo paso a paso que tiene este aspecto:
int test = 10;
NSString *stringTest = [NSString stringWithFormat:@"%d", test];
stringTest = [[stringTest stringByAppendingString:@"%"]
stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet alphanumericCharacterSet]];
stringTest = [stringTest stringByRemovingPercentEncoding];
NSLog(@"percent value of test: %@", stringTest);
o corta la mano:
NSLog(@"percent value of test: %@", [[[[NSString stringWithFormat:@"%d", test]
stringByAppendingString:@"%"] stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet alphanumericCharacterSet]] stringByRemovingPercentEncoding]);
Gracias a todos los contribuyentes originales. Espero que esto ayude. ¡Aclamaciones!
Estoy probando NSLog ([NSString stringWithFormat: @ "% @ %%", self.Ptextfield.text]); y el resultado es jsut el uitextfield.text – Ali
'NSLog' trata su primer argumento como una cadena de formato, pero ya ha formateado la cadena usando' stringWithFormat: '. Simplemente diga 'NSLog (@"% @ %% ", self.Ptextfield.text)'. –
Esto no funciona para UILocalNotification. Ver http://stackoverflow.com/a/27971848/2446178. –