Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a very basic cocoa osx app that has a text field and a button.

When you type something in to the text box and click the button it just sets a variable with the value in the text box -

- (IBAction)getText:(NSButton *)sender {
NSString *textFromField = _theText.stringValue;
}

If I type less then 7 characters in to the text box the variable gets set correctly.
If I type 7 to 11 characters in the text box the variable has garbage at the end.

Here is a copy of the All Output window -

(lldb) print textFromField
(NSString *) $0 = 0x000000010241c060 @"12345"
(lldb) print textFromField
(NSString *) $1 = 0x0000000102425260 @"1234567\xd0\xc4h$\x10"
(lldb) print textFromField
(NSString *) $2 = 0x0000000100510a30 @"123456789.\x05\x10"
(lldb) print textFromField
(NSString *) $3 = 0x00000001022370d0 @"123456789012"
(lldb)

You can see that if I type 12345 in to the text box, the variable shows 12345
But if I type 1234567 the variable shows 1234567\xd0\xc4h$\x10
It shows the extra garbage until you get up to 12 characters then it is fine again.

Any ideas why this happens?
Posted

1 solution

I figured it out.

The issue was the way Xcode displays it in debug mode.

Also, in the output window i was using "print" instead of "print object".
print object worked correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900