Need help with printf

Discussion in 'iOS Development' started by ipodtouchdude, Jul 20, 2010.

  1. ipodtouchdude

    ipodtouchdude Member

    Joined:
    Apr 18, 2008
    Messages:
    279
    Likes Received:
    3
    Device:
    iPhone 5 (Black)
    Is there a way that i can put the printf output in a UIAlertView or in a UITextView?

    oops i posted in the wrong place, can someone move this in iPhone OS Development please.
  2. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    You need to get an NSString, not write to stdout. Try +[NSString stringWithFormat:] or -[NSString initWithFormat:].

    [objc]
    NSString *literal = @"Sarah";
    int a = 7;

    NSString *str = [NSString stringWithFormat

    Please Register or Log in to view images

    "Hello, %@. Here is an integer: %d", literal, a];
    // str = "Hello, Sarah. Here is an integer: 7"
    [/objc]
    The format specifiers work the same as printf, with the addition of %@ which expects an Obj-C object (id) and sends the -[description] message to it.

Share This Page