Post Pic

sprintf with NSString

So, I have been struggling to learn Objective C. Here is a snippet of code that might be helpful. Basically you can use NSString’s initWithFormat method to create a new NSString object and use it just like sprinf function in C

[[NSString alloc] initWithFormat:@”(%f,%f)”,center.x,center.y]   

Related posts:

  1. Twitter + iPhone = MyTweet A simple twitter client using Objective C API provided by...
  2. Use NSDateFormatter To Create A Countdown App On iPhone Use NSDateFormatter to extract Date components and use it to...
  3. iPhone SDK 3.0 – Playing with Map Kit – Part 3 This is the 3 part of me Playing with Map...
  4. How to use SBJSON and TouchJSON In this post I show how to use the two...
  5. How to add CoverFlow Effect on your iPhone App – OpenFlow Hello all, The main criteria of this post is to...

Related posts brought to you by Yet Another Related Posts Plugin.

5 Responses

03.16.08

Thanks! I too am learning Objective-C and have been trying to figure out an NSString-style sprintf. This does the trick.

03.16.08

Thanks! This post was very helpful to me :)
Short and consise, just the way it should be!
mvh roger

03.16.08

[NSString stringWithFormat:@"(%f,%f)",center.x,center.y]

[...] Use initWithFormat [...]

03.16.08

Awesome :)
Sometimes its faster to use google and see such a blog post instead of search the entire apple documentation ..

Leave Your Response

* Name, Email, Comment are Required