Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Objective-C iOS
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 28-May-13 6:04am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 334
2 CPallini 275
3 DamithSL 230
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 28 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100