Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print value of a variable by NSLog?

A really basic question, I have recently started exploring Objective C and Trying to mess with one example code. However just for debugging purpose I want print value of NSString variable on console. How do I achieve this?

Basically I am a java developer, So I am looking something similar as...

String hello = "world!"; System.out.println(hello); 

My variable in this foreign language(Obj-C) is...

NSString *hello = ...calling a method to return string... 

Any hint will be appreciated!

Thank you

like image 932
TeaCupApp Avatar asked Aug 11 '11 01:08

TeaCupApp


People also ask

How do I print boolean in NSLog?

There is no format specifier to print boolean type using NSLog. One way to print boolean value is to convert it to a string. Another way to print boolean value is to cast it to integer, achieving a binary output (1=yes, 0=no).

How do I print text in Xcode?

In Swift with Xcode you can use either print() or NSLog() . print() just outputs your text.

How do I print a log in Objective C?

In order to print logs, we use the NSLog method in Objective-C programming language which we have used right from the Hello World example. Now, when we compile and run the program, we will get the following result. 2013-09-16 00:32:50.888 demo[16669] Hello, World!


1 Answers

Pretty simple:

NSLog(@"Value of hello = %@", hello); 
like image 156
Tim Dean Avatar answered Sep 23 '22 09:09

Tim Dean