xcode 在iOS中解析期间获取操作之间的时间间隔
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7603190/
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
Getting Time intervals between operations during parsing in iOS
提问by learner2010
I am parsing an xml and I would like to know how I can keep track of the time it takes to do the same.
我正在解析一个 xml,我想知道如何跟踪执行相同操作所需的时间。
I tried to use alerts, but it kept crashing my app due to the large number of alert popping up.
我尝试使用警报,但由于弹出大量警报,它一直使我的应用程序崩溃。
Is it the same if I try to run my project on my iPAD through XCODE (i.e. by selecting target as my iPAD) and if I try to run the project when the iPAD is not connected to the mac? I ask this because, when I try NSLogging the times, it comes out on the Xcode. But I feel that is it not right.
如果我尝试通过 XCODE 在我的 iPAD 上运行我的项目(即通过选择目标作为我的 iPAD),如果我尝试在 iPAD 未连接到 mac 时运行项目,是否相同?我问这个是因为,当我尝试 NSLogging 时间时,它会出现在 Xcode 上。但我觉得这样不对。
回答by Circumflex
NSLog is supposed to show in XCode. It prints a log message to the system log, which, on the iPad you have no way of seeing on the device itself.
NSLog 应该显示在 XCode 中。它会向系统日志打印一条日志消息,而在 iPad 上,您无法在设备本身上看到该消息。
If it were me, I'd do something like this:
如果是我,我会做这样的事情:
Store an NSDate variable before decoding the XML (probably as a property, since you're most likely doing XML decoding asynchronously)
在解码 XML 之前存储一个 NSDate 变量(可能作为一个属性,因为您最有可能异步进行 XML 解码)
self.timingDate = [NSDate date];
Then, when the XML has finished decoding:
然后,当 XML 完成解码时:
NSLog(@"Time taken: %f", [[NSDate date] timeIntervalSinceDate:self.timingDate]);
That will print out the amount of time spent decoding in seconds.
这将打印出解码所花费的时间(以秒为单位)。
回答by Richard Brightwell
You can use NSLog and run it while not connected to your XCode machine. Afterwards, y0u can connect it to XCode and read the console entries made while it was disconnected. Just go to the organizer and select your device's console.
您可以使用 NSLog 并在未连接到 XCode 机器的情况下运行它。之后,y0u 可以将其连接到 XCode 并读取断开连接时所做的控制台条目。只需转到管理器并选择您设备的控制台即可。
edit: You can also see the NSlog entries on the device itself by installing the Console app from the App Store.
编辑:您还可以通过从 App Store 安装控制台应用程序来查看设备本身的 NSlog 条目。