Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use printf with NSString

I need to use something like NSLog but without the timestamp and newline character, so I'm using printf. How can I use this with NSString?

like image 576
node ninja Avatar asked Sep 26 '10 00:09

node ninja


People also ask

What is NSLog in objective C?

NSLog outputs the date, time, process name, process ID, and thread ID in addition to the log message. printf just outputs the message. NSLog requires an NSString and automatically adds a newline at the end. printf requires a C string and does not automatically add a newline.

What does NSString mean?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.

Do I need to release NSString?

If you create an object using a method that begins with init, new, copy, or mutableCopy, then you own that object and are responsible for releasing it (or autoreleasing it) when you're done with it. If you create an object using any other method, that object is autoreleased, and you don't need to release it.


1 Answers

You can convert an NSString into a UTF8 string by calling the UTF8String method:

printf("%s", [string UTF8String]); 
like image 145
Jacob Relkin Avatar answered Oct 21 '22 01:10

Jacob Relkin