Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Newbie Question

Newbie Question
Thread Tools
Grizzled Veteran
Join Date: Sep 1999
Location: Boston, MA USA
Status: Offline
Reply With Quote
Jun 8, 2001, 03:54 PM
 
I'm running into some problems dealing with some basic issues. For example, I want to convert an integer to a string. Another example - random numbers. The regular C syntax doesn't seem to work, and I'm not finding answers in the docs.

I'm not really looking for answers to these specific questions, but rather suggestions on where/how to find the answers myself.

Thanks in advance,
     
Mac Elite
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jun 9, 2001, 04:25 AM
 
For tutorials, source code, and other info, try:
StepWise
and
Cocoa Dev Central

As for your integer question, try
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier><font color = green>int</font> a;
...
<font color = green>return</font> [NSString stringWithFormat:<font color = orange>@"%d"</font>,a];</font>[/code]
"%d" is the format representation for an integer. See some printf documentation for more information.

You could also try
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier><font color = green>int</font> a;
...
<font color = green>return</font> [[NSValue valueWithInt:a] stringValue];</font>[/code]
which might be cheaper than evaluating a format string.

And for the random number, what exactly are you trying to do? One common trick is to set the seed when you start your program
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>-(<font color = purple>id</font>)init {
<font color = purple>self</font> = [<font color = purple>super</font> init];
srandom(time(<font color = green>NULL</font>));
<font color = green>return</font> <font color = purple>self</font>;
}</font>[/code]
and then later in the program, use some math to get your number. For example, if I want an int between 0 and 10, I'd use
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier><font color = green>int</font> a;
...
a = random()%<font color = blue>10</font>;</font>[/code]
Does that help any?

[ 06-09-2001: Message edited by: starfleetX ]
The server made a boo boo. (403)
     
Grizzled Veteran
Join Date: Sep 1999
Location: Boston, MA USA
Status: Offline
Reply With Quote
Jun 9, 2001, 12:35 PM
 
That does help a huge amount. And I looked at the Obj-C Tutorial - I note it has what appears to be a language guide (although not an entirely standalone one - it's an accompaniment to another full C language guide). I think this is mostly what I'm looking for.

Now, if I could just do a search within dev central docs.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jun 10, 2001, 03:51 AM
 
Originally posted by dogzilla:
<STRONG>Now, if I could just do a search within dev central docs.</STRONG>
You can. You have a local copy anyways, which when launched with Apple Help Viewer will let you search, and when you go to the one on developer.apple.com/techpubs I seem to remember there's a search option there.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:49 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2