Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 20, 2008, 07:49 AM   #1
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Convert float to NSString and vice versa?

timeRemaining is a float,
timeRemainingLabel is a UILabel,
roundTime is a UITextField,

all 3 are declared in my header.

I'm getting errors with these two lines of code...

Code:
timeRemaining = roundTime.text;
I have no idea how to convert a NSString to a float... I was crossing my fingers this would work... apparently it didn't as I got this error

Quote:
error: incompatible types in assignment
Code:
timeRemainingLabel.text = (@"Time Remaining: %f Seconds", timeRemaining);
I was actually expecting this one to work... I thought it would work just like in C where %f would be replaced with timeRemaining. Apparently not because I got this error
Quote:
error: incompatible type of argument 1 of 'setText:'
Well... at least I havn't had the same problem twice yet... it's a sign I'm learning from my mistakes, right? Good judgement comes from experience; experience comes from bad judgement.

Thanks for all the help people have been giving, and thanks in advance for help with this too.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 20, 2008, 08:10 AM   #2
detz
macrumors 65816
 
Join Date: Jun 2007
something = [NSString stringWithFormat:@"%f",floatValue];
detz is offline   0 Reply With Quote
Old Aug 20, 2008, 08:10 AM   #3
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Did you even open the documentation? In the time it took you to type that you could have found the floatValue method of NSString.

As for turning floats into NSStrings you have a few options. The closest to what you have posted (which makes no sense at all, are you expecting the compiler to magically turn that into a method call for you) is also clear in the documentation: the convenience stringWithFormat: factory method.
robbieduncan is offline   0 Reply With Quote
Old Aug 20, 2008, 09:31 AM   #4
ArtOfWarfare
Thread Starter
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Sorry, I did check the documentation but I didn't understand how to use stringWithFormat properly.

Thanks detz for giving an example of how to use stringWithFormat.

And thanks robbieducan for pointing out the method I overlooked... floatValue.

It works now... although my timer doesn't seem to be working properly... hopefully I can fix that without asking for help on the forums...

Edit: Now the timer works. Just for the record... if you're making a timer that repeats every 0.01 seconds... you shouldn't make it send a message to the NSLog every time...
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)

Last edited by ArtOfWarfare; Aug 20, 2008 at 09:40 AM.
ArtOfWarfare is offline   0 Reply With Quote
Old Sep 19, 2008, 09:40 PM   #5
aaronvegh
macrumors newbie
 
Join Date: Dec 2001
Quote:
Originally Posted by robbieduncan View Post
Did you even open the documentation? In the time it took you to type that you could have found the floatValue method of NSString.

As for turning floats into NSStrings you have a few options. The closest to what you have posted (which makes no sense at all, are you expecting the compiler to magically turn that into a method call for you) is also clear in the documentation: the convenience stringWithFormat: factory method.
That doesn't make you any less of a jackass. Some people don't have the knowledge you do, so please, cut them some slack. Detz's concise response was exactly what I was Googling for.
__________________
15-inch MacBook Pro, 2.33GHz, OS X 10.5
aaronvegh is offline   0 Reply With Quote
Old Sep 20, 2008, 11:55 AM   #6
ArtOfWarfare
Thread Starter
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by aaronvegh View Post
That doesn't make you any less of a jackass. Some people don't have the knowledge you do, so please, cut them some slack. Detz's concise response was exactly what I was Googling for.
No, he was completely right. I'd become too dependent on asking people for help rather than taking the time to check the documentation. Don't call him names just for pointing out my flaws... how else would people learn they were doing things wrong? Their ego will tell them they're doing it right so they'll have to have someone else tell them they're wrong.

Quote:
HI
can you help me that i can write a sample code for a login page with 2 field user and pass and a button for submit .
Thanks.
have you a good document that explain code?
This seems rather off topic but if you check the ADC page I'm pretty sure that one is anwsered in the FAQ...

http://developer.apple.com/iphone/ge...rtedfaq.action

I'm not going to give you the exact answer... instead I'll let you learn how to check the adc documentation to find answers yourself.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Sep 20, 2008, 12:06 PM   #7
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by ArtOfWarfare View Post
No, he was completely right.
Ah, thanks! I was simply ignoring the other dude! I hope your coding is going well

Quote:
Originally Posted by ArtOfWarfare View Post
This seems rather off topic but if you check the ADC page I'm pretty sure that one is anwsered in the FAQ....
So far off-topic it's got it's own badly titled thread. Although the advice in it is basically the same as yours.
robbieduncan is offline   0 Reply With Quote
Old Sep 20, 2008, 03:37 PM   #8
Sbrocket
macrumors 65816
 
Sbrocket's Avatar
 
Join Date: Jun 2007
Location: /dev/null
Quote:
Originally Posted by aaronvegh View Post
That doesn't make you any less of a jackass. Some people don't have the knowledge you do, so please, cut them some slack. Detz's concise response was exactly what I was Googling for.
aaronvegh -

People answering questions here sometimes come off as rude because the questions asked in those cases are typically rudimentary, with answers that could be readily obtained from a quick search through Apple's doc sets. Using documentation is a key skill that less knowledgeable or developers that are just starting out will find it in their best interest to develop should they want to avoid relying on others to answer every simple question (and probably getting a snappy answer in reply.)
__________________

Unibody MBP 15" | 2.53GHz | 4GB DDR3 | 320GB @ 7200RPM
Sbrocket is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: How do I convert an NSData object to an NSDictionary object, and vice versa? moonman239 iPhone/iPad Programming 6 May 2, 2014 01:17 PM
Do Iphones in USA work in Canada and vice versa? pauly1 iPhone 2 Nov 21, 2013 04:34 PM
General: Why can't we just make iPhones run android and vice-versa? cnguyen0320 Jailbreaks and iOS Hacks 7 Nov 2, 2012 01:55 AM
Why buy Windows RT instead of iPad (and vice versa)? ozaz Alternatives to iOS and iOS Devices 25 Sep 18, 2012 07:23 PM
Dropbox in Skydrive (or vice versa) DrDoug Mac Applications and Mac App Store 4 Jun 29, 2012 06:14 AM

Forum Jump

All times are GMT -5. The time now is 04:08 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC