nslog

NSLog - How to print object name?

依然范特西╮ 提交于 2019-12-31 00:30:28
问题 Consider, NSString *myString = @"Welcome"; NSLog(@"%@",myString); will print Welcome in console. Can I print the string like " myString: Welcome "? I mean, can I get the object name(" myString ") along with object value(" Welcome ")? 回答1: Use the following code: #define stringVariable(x) NSLog( @"%s:%@",#x, x) NSString *myString=@"Welcome"; stringVariable(myString); Note: The general principle is that when you put a # in front of an argument within the body of a #define, the preprocessor

Calling NSLog from C++: “Format string is not a string literal (potentially insecure)”

不羁的心 提交于 2019-12-30 06:47:28
问题 When I call NSLog from C++, Xcode complains that the format string passed to NSLog is not a literal string. Here's a line of code that triggers the warning: NSLog(CFSTR("Leaking?")); I'm not aware of any way to code a literal NSString in C++, and I don't see a relevant warning I can turn off in the project settings. Is there a way to call NSLog from C++ without triggering this message? I'm using Xcode 4.2.1. Edit: This really is C++ code. I usually avoid Objective-C++, sticking to either

Enable and Disable NSLog in DEBUG mode

那年仲夏 提交于 2019-12-29 10:12:11
问题 I want to enable NSLog when I am in debug and disable it otherwise. A very simple thing is: #ifdef DEBUG NSLog(@"My log"); #endif But all this #ifdef and #endif is borring... :( So I try other thing: (.pch is good place to put it) #ifdef DEBUG # define NSLog(text) NSLog(text); #else # define NSLog(text) #endif This work very fine (isn't recursive). But the problem is that NSLog have infinite arguments. void NSLog(NSString *format, ...) How I solve this to work in preprocessor mode? -- Edit --

Viewing the console log in iOS7

两盒软妹~` 提交于 2019-12-29 04:14:46
问题 Prior to iOS7, if I wanted to view the output log of an app running on an iOS device, I would use one of: https://itunes.apple.com/au/app/system-console/id431158981?mt=8 https://itunes.apple.com/au/app/console/id317676250?mt=8 However, since upgrading to iOS7, both of these don't seem to be recording the log output of any app on my phone. Would this be due to a new setting on my phone? Or has iOS7 changed the way in which logging is handled such that these two apps are now broken? 回答1: We're

Viewing the console log in iOS7

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-29 04:14:11
问题 Prior to iOS7, if I wanted to view the output log of an app running on an iOS device, I would use one of: https://itunes.apple.com/au/app/system-console/id431158981?mt=8 https://itunes.apple.com/au/app/console/id317676250?mt=8 However, since upgrading to iOS7, both of these don't seem to be recording the log output of any app on my phone. Would this be due to a new setting on my phone? Or has iOS7 changed the way in which logging is handled such that these two apps are now broken? 回答1: We're

NSLog 10b meaning?

牧云@^-^@ 提交于 2019-12-28 04:31:28
问题 Whenever I use NSLog(), it always shows this mysterious "10b" next to the process ID. I know that this is tied somehow to the thread where the NSLog() call was made, but what exactly does it mean? When I try NSLog() from a different thread in the same process, I will get values like 1003, 1103, and 1403. Here is the "Hello, World!" output or NSLog() for reference: 2009-09-15 10:26:38.591 delme[38163:10b] Hello, World! 回答1: It’s the thread ID; specifically, it’s the mach thread ID. You can get

iOS:UIImageView添加点击事件

人盡茶涼 提交于 2019-12-25 14:15:52
UIImageView并不像UIButton那样点击鼠标就可以关联点击事件,也不像Android里有onClickListener,这个时 候就需要借助UITapGestureRecognizer类,从类名上就可以看出,这个类就是用于处理tap(单击)事件的。 创建两个UIImageView对象,imageView1和imageView2 [imageView1 setUserInteractionEnabled : YES ]; [imageView2 setUserInteractionEnabled : YES ]; [imageView1 addGestureRecognizer :[[ UITapGestureRecognizer alloc ] initWithTarget : self action : @selector ( clickCategory :)]]; [imageView2 addGestureRecognizer :[[ UITapGestureRecognizer alloc ] initWithTarget : self action : @selector ( clickCategory :)]]; 经测试,多个UIImageView不能共用一个UITapGestureRecognizer对象,之前调用的会没效果。

How to print the retain count of an object?

心已入冬 提交于 2019-12-25 08:55:03
问题 I am trying to print out the retain count of an object in the terminal using NSLog. Here is my code: NSNumber *myInt=[[NSNumber alloc] initWithInteger: 100]; NSLog(@"myInt retain count=%d",[myInt retainCount]); The result should be 1 but what I have got at the terminal is -1. I tried to use %u instead of %d and ended up getting 4294967295 as result. Does anyone know why this happens? 回答1: Before @bbum gets here I get to say this: Don't rely on -retainCount in your code It doesn't give you

How to convert NData populated with hex values to NSString

╄→尐↘猪︶ㄣ 提交于 2019-12-25 04:58:19
问题 I have a NSdata object that is populated with a bunch of information thats formated in hex.. I am trying to convert it into its proper string representation but am struggling to have any success. One thing I have tried is to simply put it into a NSString and then NSLog it with a special character identifier thingy.. forgot the word (%02x), However to do this I am encoding it to NSUTF16.. which i dont want to do.. I mearly want to see exactly whats the data I am getting looks like as a

How to use iOS OSLog with Xamarin?

安稳与你 提交于 2019-12-25 03:17:59
问题 How can I use the iOS OSLog in Xamarin.iOS? I did succeed in using NSLog as follows, but I see no way of setting the subsystem (to the bundle identifier) with NSLog so that I can use that to filter the logs in Console.app. public class Logger { #if DEBUG [DllImport(ObjCRuntime.Constants.FoundationLibrary)] private extern static void NSLog(IntPtr message); #endif public void WriteLine(string line) { #if DEBUG using (var nss = new NSString(line)) { NSLog(nss.Handle); } #endif } } 回答1: OSLog is