ios 如何通过 NSLog 打印变量的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7019744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to print value of a variable by NSLog?
提问by TeaCupApp
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
谢谢
回答by Tim Dean
Pretty simple:
很简单:
NSLog(@"Value of hello = %@", hello);
回答by Madhu
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