Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Yellowstone2012

macrumors regular
Original poster
Feb 3, 2011
108
0
This has been bugging me; how do I set a NSTextField to output a string from multiple NSTextFields?

In VB.NET you could do this:

Code:
TextBox1.Text = TextBox2.Text & TextBox3.Text


I am wanting to know how to do the same with Obj-C. I would also like to know the code such as to create a new line in string. (TextBox1.Text = "Test" & vbNewLine ; code for new line in visual basic)

Thanks!
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Code:
textBox1.stringValue = 
  [textBox2.stringValue stringByAppendingString:textBox3.stringValue];

Code:
textBox1.stringValue = @"Test\n";

This is basic stuff. You should pick up a good book on Objective-C and Cocoa programming.
 

PatrickCocoa

macrumors 6502a
Dec 2, 2008
751
149
Cocoa

I see jiminaus has beaten me to the punch. [NSString stringByAppendingString] is the way to go.

More importantly, as jiminaus says, is to get very, very comfortable with surfing the Cocoa documentation. Get used to looking up a class and just paging through the methods. Cocoa naming conventions are fairly consistent and human readable, so this is a good technique.

To get to the docs, in Xcode go to Window / Organizer / Documentation. Type NSString in the search bubble. Then in the breadcrumb trail at the top of the screen click on NSString Class Reference, select instance methods, and read.
 

Yellowstone2012

macrumors regular
Original poster
Feb 3, 2011
108
0
Code:
textBox1.stringValue = 
  [textBox2.stringValue stringByAppendingString:textBox3.stringValue];

Code:
textBox1.stringValue = @"Test\n";

This is basic stuff. You should pick up a good book on Objective-C and Cocoa programming.

Thanks for the code!

Which book do you recommend? Thanks!
 

Yellowstone2012

macrumors regular
Original poster
Feb 3, 2011
108
0
I see jiminaus has beaten me to the punch. [NSString stringByAppendingString] is the way to go.

More importantly, as jiminaus says, is to get very, very comfortable with surfing the Cocoa documentation. Get used to looking up a class and just paging through the methods. Cocoa naming conventions are fairly consistent and human readable, so this is a good technique.

To get to the docs, in Xcode go to Window / Organizer / Documentation. Type NSString in the search bubble. Then in the breadcrumb trail at the top of the screen click on NSString Class Reference, select instance methods, and read.

Thanks. I've just looked through the docs and found
[stringByAppendingFormat:mad:" %@ %@", ...];

I wrote the code, and my test app does exactly what I want it to do. It's printing my first name, space, and last name into another NSTextField. (label)


I could just learn it on my own via the documentation.

@"Thanks for the help!";
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.