The Mac Observer

 
   
 
Casting int to NSString.
Posted: 16 February 2002 12:38 PM [ Ignore ]
Moderator
Avatar
Total Posts:  3821
Joined  2001-06-15

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 (1990[now yearOfCommonEra] 4i++)
    
{
    
// 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… icon_confused.gif

<font size=-1>[ This Message was edited by: LaurieF on 2002-02-15 20:30 ]</font>

 Signature 

Laurie Fleming - the singing geek

@LaurieFleming

Profile
 
 
Posted: 16 February 2002 12:31 PM [ Ignore ] [ # 1 ]
stars_5
Total Posts:  1162
Joined  2001-11-02

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

as 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

Profile
 
 
Posted: 16 February 2002 12:38 PM [ Ignore ] [ # 2 ]
stars_5
Total Posts:  1162
Joined  2001-11-02

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

Profile
 
 
   
 
 

Apple Stock Quote (AAPL)

Loading...

Hot Topics

TMO Express

Join the TMO Express Daily Newsletter to get the latest Mac headlines in your e-mail every weekday. Find out more!

Top Deals From DealBrothers.com

Recent Features

Support The Mac Observer

We noticed you may be running AdBlock on your computer. It takes real money to run this site and to deliver the news, tips, and opinions you love to read.

If you wish to block the ads that pay for the creation of our content, we ask that you instead support TMO Directly, either with a $5 monthly recurring contribution, or a one-time donation of any amount of your choice. Thanks!

Subscribe with Paypal Donate with Paypal