views:

37

answers:

2

Hi all !

I need to create a string using results of a textfield.

I use :

>     NSString *username = [NSString stringWithFormat:myTextField.txt];

but i get the warning : Format not a string literal and no format arguments.

Everything works but like i use more than 10 times this syntax i would like to erase this warning. thanks to all !

+3  A: 

In iOS 4 you must do as follows in order to get rid of the warning:

NSString *username = [NSString stringWithFormat:@"%@", myTextField.txt];
unforgiven
Warnings aside this is the correct way to use `stringWithFormat`.
Evadne Wu
+2  A: 

That's... not really what -stringWithFormat: is for. Use

NSString *username = [NSString stringWithString:myTextField.text];

or

NSString *username = [[myTextField.text copy] autorelease];
Noah Witherspoon
myTextField.txt, not .text :)
Emil
I assumed that was a typo—if it's a UITextField, the property is “text”, not “txt”.
Noah Witherspoon
yea it was thanks
sarlin13

related questions