如何通过NSLog打印变量的值?

时间:2022-05-26 22:39:23

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?

一个非常基本的问题,我最近开始探索Objective C并试图弄乱一个示例代码。但是出于调试目的,我希望在控制台上打印NSString变量值。我该如何实现这一目标?

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

基本上我是一个java开发人员,所以我看起来像...

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

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

我的外语变量(Obj-C)是......

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

Any hint will be appreciated!

任何提示将不胜感激!

Thank you

谢谢

2 个解决方案

#1


47  

Pretty simple:

很简单:

NSLog(@"Value of hello = %@", hello);

#2


11  

NSLog(@"%@",hello);

Based On data type %@ changes as follows

基于数据类型%@更改如下

For Strings u use %@
For int  u use %i
For float u use %f
For double u use %lf

#1


47  

Pretty simple:

很简单:

NSLog(@"Value of hello = %@", hello);

#2


11  

NSLog(@"%@",hello);

Based On data type %@ changes as follows

基于数据类型%@更改如下

For Strings u use %@
For int  u use %i
For float u use %f
For double u use %lf