nslog

【objective-c】初次学习objective-c问题汇总... 【暂完,待修改错误】

≡放荡痞女 提交于 2019-12-10 09:21:58
---------------------------------------------------------------------------------------- 这本书,我已经看过两遍,那两遍都是在买mac pro之前看的,目的是...因为语法怪怪的很有趣。 好吧,也许还是有那么点歪心思的,现在买了电脑,第三遍看了,(⊙o⊙)…の,实践了才知道,中间会遇到这么多很纠结的问题。不过还好,速度比之前看要快很多很多了。。。 我 是分割线 终于全部实践了一次并写了一些小小的东西,不过还是不太熟练。接下来会继续看另外一本很基础的书,不过这本书就不会做笔记了,同时会跟着新买的一本口碑超赞的书进行实践练习,会有新笔记的。 这篇笔记估计不会有太多的更新了,但如果在后面的学习和回顾中发现笔记里有错误的理解和看法,会进行修改与调整的。 如果在看这篇笔记的你发现有什么问题,一定记得给我评论留言指出,O(∩_∩)O谢谢了!~ ---------------------------------------------------------------------------------------- 理解不透的问题: 1、内存管理:虽说可以自动管理内存,但是过来人说这个必须要懂,要非常懂。。。 2、类别和委托 3、NSCoding :对象的编码和解码 4、并发 5、NSPredicate

How to invoke method with CVaListPointer parameters in Swift

不打扰是莪最后的温柔 提交于 2019-12-08 16:18:20
问题 How should I invoke the following method? The method belongs to a class that prints logs. func log(format: String!, withParameters valist: CVaListPointer) What I want to achieve, would look like this in Objective-C: NSLog(@"Message %@ - %@", param1, param2); Any ideas? 回答1: CVaListPointer is the Swift equivalent of the C va_list type and can be created from an [CVarArgType] array using withVaList() . Example: func log(format: String!, withParameters valist: CVaListPointer) { NSLogv(format,

iOS - How to view NSLog and printf output in ssh session on phone?

寵の児 提交于 2019-12-08 13:42:55
问题 I have a simple iPhone App that uses an NSLog and several printf statements. The app is a simple test app that I created to test serial communication on the iPhone (3GS). Obviously I can not test serial com with the iOS Simulator, so I have my device unplugged from the computer after I click Run from within Xcode. I installed syslogd from Cydia, and tail /var/log/syslog allows me to monitor certain log messages. However when I open my app and it reaches the NSLog portion of the code I don't

objective-c why does nslog show strings inbetween double quotation marks “ ”?

蹲街弑〆低调 提交于 2019-12-08 10:19:51
问题 I am loading a nsarray from a textfile: NSArray *noWords = [[NSArray alloc] initWithArray: [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"untitled" ofType:@"txt"] encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"]]; Untitled.txt contains: alfa beta (geologi). beta jaha javel jam (geologi) en jamen jamen jamen jax. (geologi)jammen det var æhæhæ øhøh på tide .(geologi),be;ta; tiden men but men aha beta NSLog (@"noWords : %@", noWords);

How can I easily redirect the console output in a NSTextView?

霸气de小男生 提交于 2019-12-08 09:47:52
问题 Suppose you have the code of a Cocoa app which logs its own messages through NSlogs and printfs to the Console output. My goal is to redirect all this output into a separate NSWindow in a NSView. How can I achieve this in a way that minimizes the amount of code to rewrite makes it possible to revert back maximizes the reuse of written code (the usual software engineering guide lines)? 回答1: Soon after your program starts use the dup(2) call to make duplicate File Descriptors for fd 1 (stdout)

ios define NSLog debug 应用发布nslog注释

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 13:15:56
1 选择工程的Target -> Build Settings -> Preprocessor Macros. 如图,默认 Debug项,是“DEBUG=1”. 2 在程序中设置全局宏定义 在程序的 ApplicationName-Prefix.pch 文件中,加入如下,很简单 #ifdef DEBUG_MODE #define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) #else #define DLog( s, ... ) #endif 3 这样就设置好了,测试 在任意ViewController.m中写入 DLog(@"1234"); 结果: 2012-07-25 17:09:54.448 xxxx[7094:707] <0x28f790 ViewController.m:(64)> 1234 这样发布的时候DLog就不会有输出了。  在Objective-c开发程序的时候,有专门的日志操作类NSLog,它将指定的输出,输出到(stderr),我们可以利用Xc ode的日志输出窗口

NSLog() vs printf() when printing C string (UTF-8)

只愿长相守 提交于 2019-12-07 12:18:09
问题 I have noticed that if I try to print the byte array containing the representation of a string in UTF-8, using the format specifier "%s", printf() gets it right but NSLog() gets it garbled (i.e., each byte printed as-is, so for example "¥" gets printed as the 2 characters: "¬•"). This is curious, because I always thought that NSLog() is just printf() , plus: The first parameter (the 'format') is an Objective-C string, not a C string (hence the "@"). The timestamp and app name prepended. The

How to NSLog calling function

久未见 提交于 2019-12-07 09:41:26
问题 Not the function calling the NSLog or Dlog but function that call that function. I created a class +(void) computeTime:(void (^)())block { NSDate * currentTime = [NSDate date]; block(); DLog ("Time Running is: %f", [[NSDate date] timeIntervalSinceDate:currentTime); } So everytime there is an operation whose time I want to measure I will put that in a block instead. and do [Tools computeTime:^{//operation}]; However, I want to know the function that call that computeTime. How do I do so? 回答1:

在release版本禁止输出NSLog内容

你。 提交于 2019-12-06 21:59:12
前提: 在XCode做开发调试时往往需要打印一些调试信息做debug用,大家知道当打印信息的地方多了之后在模拟器上跑可能不会有什么问题,因为模拟器用的是电脑的硬件但是当应用跑在设备上时这些输出语句会在很大程度上影响应用的性能,针对这种问题可以写一些宏来控制这些调试信息的输出。 在release版本禁止输出NSLog内容 因为NSLog的输出还是比较消耗系统资源的,而且输出的数据也可能会暴露出App里的保密数据,所以发布正式版时需要把这些输出全部屏蔽掉。 我们可以在发布版本前先把所有NSLog语句注释掉,等以后要调试时,再取消这些注释,这实在是一件无趣而耗时的事!还好,还有更优雅的解决方法,就是在项目的prefix.pch文件里加入下面一段代码,加入后,NSLog就只在Debug下有输出,Release下不输出了。 如何实现: 在 -Prefix.pch( pch全称是“precompiled header”,也就是预编译头文件,该文件里存放的工程中一些不常被修改的代码,比如常用的框架头文件,这样做的目的提高编译器编译速度。我们知道当我们修改一个工程中某个文件代码时候,编译器并不是重新编译所有所有文件,而是编译改动过文件的,假如pch中某个文件修改了,那么pch整个文件里包含的的其他文件也会重新编译一次,这样就会消耗大量时间

How do I log russian text or non-latin?

坚强是说给别人听的谎言 提交于 2019-12-06 15:03:54
Everything works well in the previous version of XCode. But today in the XCode 4.3.2 I have a problem. How do I log russian text or non-latin? NSLog(@"russian text: русский текст"); NSString *text = @"russian text: русский текст"; const char *textC = [text UTF8String]; NSString *getText = [NSString stringWithCString:textC encoding:NSUTF8StringEncoding]; NSLog(@"___text: %@", getText); My logs russian text: —Ä—É—Å—Å–∫–∏–π —Ç–µ–∫—Å—Ç ___text: russian text: —Ä—É—Å—Å–∫–∏–π —Ç–µ–∫—Å—Ç UPDATE: The bug take place only on real device (ipod touch 5.1). It works properly on iphone simulator. Works fine