views:

50

answers:

1

When I try to get the text of a UITextField it returns a random integer. Here's the code I used:

NSLog(@"Field Text: %d", field.text);

field being the UITextField. And in the debugger it returns an random number, for example 29876208 when there is text in the UITextField.

+3  A: 

Euhm, I think you are either getting back some kind of representation of the memory address the text is located, or just some bull-sh*t.

You should try to do this:

NSLog(@"Field text : %@", field.text);

The problem is the formatter you are using.

Wim Haanstra
Just to clarify: `%d` in a format string means "print as an int", whereas `%@` means "print as an NSObject". So using `%d` will, as Wim Haanstra alluded to, print out the memory address of the `NSString` `field.text`. Using `%@` will print _the contents_ of that `NSString`. Also, note that `%@` is only valid in format strings in Apple's CF/NS frameworks, it isn't valid in `printf` and other non-Apple specific format strings.
Nick Forge
Thanks very much! I didn't know there were different formatters. So simple!
Joshua