Typecasting stuff to strings?

Discussion in 'iOS Development' started by Kukumber, Mar 4, 2009.

  1. Kukumber

    Kukumber New Member

    Joined:
    Nov 10, 2008
    Messages:
    328
    Likes Received:
    0
    Device:
    2G iPod touch
    Typecast stuff to strings?

    Ok I'm very new to Objective-C and I did search this forum and the web extensively but I haven't found an answer...

    I am trying to build a very basic app,
    I want to enter 2 floats and multiply them, then display the result in a UITextField (hey, I said it was simple ).

    Reading and writing from/to those UITextFields works just fine, multiplying works fine ( newValue = [inValue1.text floatValue] * [inValue2.text floatValue]; )

    But NSNumber does not appear to have a string/stringValue method, and NSString doesn't have a initWithFloat method.

    I'm sure its really obvious and I'm a fool for not realizing how to do it, but I don't know where else to ask!

    Please help a noob out

    Please Register or Log in to view images

  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    NSString *aString = [NSString stringWithFormat

    Please Register or Log in to view images

    "%f", someFloat];
  3. Kukumber

    Kukumber New Member

    Joined:
    Nov 10, 2008
    Messages:
    328
    Likes Received:
    0
    Device:
    2G iPod touch
    Thanks!

    It seems though I created the NSNumber wrong, because it does have a stringValue method and now it works

    Please Register or Log in to view images

  4. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    is there such thing as an NSNumber? I've never heard of it? NSInteger? NSUInteger?
  5. Kukumber

    Kukumber New Member

    Joined:
    Nov 10, 2008
    Messages:
    328
    Likes Received:
    0
    Device:
    2G iPod touch
    NSNumber handles integers and floats...I think...
  6. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    Oh OK thanks. You learn something new everyday.

    Please Register or Log in to view images

  7. awesome761

    awesome761 Banned

    Joined:
    Aug 28, 2008
    Messages:
    945
    Likes Received:
    0
    master of xcode (and other types of codes

    Please Register or Log in to view images

    )
  8. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    Ok anyone could of posted that, I could of posted that, it doesn't mean I'm a master. Although Skylar is. (well nearly) Thats just about one of the easiest thing in Cocoa Touch to do. No offense intended
  9. Kukumber

    Kukumber New Member

    Joined:
    Nov 10, 2008
    Messages:
    328
    Likes Received:
    0
    Device:
    2G iPod touch

Share This Page