You are here: Home → Forum Home → The Mac Observer Forums → Design & Create → Thread
Casting int to NSString.
-
This should be *really* obvious, but it ain’t to me.
I have a popUpButton with years from 1990 to a wee way ahead. I want to populate each row with the year description and found this was the easiest way for me to do it. But it can’t be the best. Or easiest.
// Populate the year button until two years in the future.
for (i = 1990; i < [now yearOfCommonEra] + 4; i++)
{
// There should be, and probably is, a straight-forward casting method for
// integer->char...
[yearButton addItemWithTitle:[NSString stringWithFormat:@"%i", i]];
[[yearButton lastItem] setTag:i];
}How change I implement the addItemWithTitle without going through the indirect stringWithFormat cast? I suppose I could slip atoi() in there, but is there an Objective-C way of going about it? I know exactly how to do it in SAS/AF Frame, but there’s no such beast under OS X.
I’m learning all the time…

<font size=-1>[ This Message was edited by: LaurieF on 2002-02-15 20:30 ]</font>
Signature
Laurie Fleming - the singing geek
@LaurieFleming
-
I thought NSString had a method to do just that. no?
huh, nothing here
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSString.htmlas you said, you could always atoi, then initwithCstring
[edit] does string with format do it?
<font size=-1>[ This Message was edited by: EDGar on 2002-02-16 17:35 ]</font>Signature
All statements are to be taken with a grain of salt
-
silly me, I just read you post a little more clearly… It looks like stringwithformat is the way to go. maybe someone else has a better idea?
<font size=-1>[ This Message was edited by: EDGar on 2002-02-16 17:40 ]</font>
Signature
All statements are to be taken with a grain of salt

