随着新手大量涌入Xcode,我确信有很多Xcode提示和技巧可供分享.
你的是什么?
请原谅我的无知,但在iPhone模拟器中运行iPhone应用程序时,有些事情一直困扰着Xcode调试器.
有时,当我在Interface Builder中搞砸了一些东西时,我在运行时得到一个未处理的异常,然后我被抛回Xcode.我唯一看到的是单行"未捕获的异常"或类似的东西.从我所看到的,没有其他信息,更不用说堆栈跟踪或任何其他有用的信息.
在过去十年左右的时间里,我一直在使用Visual Studio进行开发,而且我习惯于获得一个很好的堆栈跟踪并在发生类似情况时完成异常信息.
我确信我只是遗漏了一些非常明显的东西......希望......
我在Xcode 4.5.1上.我认为这是我看到的相对较新的行为.
我更喜欢在启用"All Exceptions"断点的情况下开发和测试我的项目.
我一直在遇到一个场景,我正在将缩略图图片加载到tableview中的单元格,在这里我得到一个__cxa_throw异常.当我点击"继续执行程序"按钮时,Xcode继续它的快乐方式.我得到了缩略图.应用似乎工作正常.我正在寻找一些关于如何确定这是否可以安全忽略的提示.就像了解堆栈跟踪的一些指示一样?或者是其他东西?
以下是代码片段:
NSString *imageStr = item.thumbURL;
imageStr = [imageStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *imageURL;
if (![imageStr isEqualToString:@""]) {
imageURL = [NSURL URLWithString:imageStr];
NSLog(@"imageURL: %@",imageURL);
if (imageURL == nil) {
NSLog(@"imageUrl was nil for string: %@",imageStr);
} else {
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
//spinner.frame = CGRectMake(cell.imageView.frame.size.width/2,cell.imageView.frame.origin.y + cell.imageView.frame.size.height/2,cell.imageView.frame.size.width,cell.imageView.frame.size.height);
spinner.frame = CGRectMake(10,20,40,40);
[spinner startAnimating];
[cell addSubview:spinner];
dispatch_queue_t downloadQueue = dispatch_queue_create("thumbnail downloader", NULL);
dispatch_async(downloadQueue, ^{
NSLog(@"Network request for tour_thumb image: %@",imageStr);
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:imageURL]];
dispatch_async(dispatch_get_main_queue(), …Run Code Online (Sandbox Code Playgroud) 我得到以下索引超出范围错误:
*** Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x2263052 0x24c7d0a 0x224fdb8 0x2f4a7 0x2264ec9 0x81e299 0x81e306 0x75aa30
0x75ac56 0x741384 0x734aa9 0x39a9fa9 0x22371c5 0x219c022 0x219a90a 0x2199db4
0x2199ccb 0x39a8879 0x39a893e 0x732a9b 0x1e5b 0x1dc5 0x1)
Run Code Online (Sandbox Code Playgroud)
我确切地知道错误意味着什么,但我发现这些错误很难修复,因为由于某种原因,调用堆栈没有告诉我调用数组的代码行.这是来自线程1的调用堆栈:
#0 0x9706d9c6 in __pthread_kill ()
#1 0x93e2cf78 in pthread_kill ()
#2 0x93e1dbdd in abort ()
#3 0x02859e78 in dyld_stub__Unwind_DeleteException ()
#4 0x0285789e in default_terminate() ()
#5 0x024c7f4b in _objc_terminate ()
#6 …Run Code Online (Sandbox Code Playgroud) Xcode/objective c并没有真正打印出有用的堆栈跟踪.我的应用程序崩溃了,该死的东西只给我45353453,34524323,6745345353,457634524234这样的数字.完全没用.
所以我想制作一个NSLog(); 在我的整个应用程序中的每个方法的开头.但也许有一种更简单的方法来找出真正的堆栈跟踪,人性可读?不仅在应用程序启动或崩溃时,而且在所有发生的活动中始终如此?会帮助调试很多.
我一直用于XCode的一个有用提示是在异常上添加断点.
我想知道为什么我们需要添加两个断点 - 一个用于objc_exception_throw,一个用于[NSException raise].
一个人覆盖的情况是另一个没有?
我曾经从模拟器中运行的应用程序中获取异常详细信息,如下所示:
po $eax
Run Code Online (Sandbox Code Playgroud)
自从我升级到XCode 4.6后,它就停止了工作; 我总是得到这个错误:
error: warning: couldn't get object pointer (substituting NULL):
Couldn't find '_cmd' with appropriate type in scope
Couldn't materialize struct: Couldn't read eax (materialize)
Errored out in Execute, couldn't PrepareToExecuteJITExpression
Run Code Online (Sandbox Code Playgroud)
我见过人们推荐使用这个:
register read eax
Run Code Online (Sandbox Code Playgroud)
但这给了我这个错误:
eax = error: unavailable
Run Code Online (Sandbox Code Playgroud)
如何在XCode 4.6中获取异常详细信息?
我暂停了我的应用程序并尝试将某些内容打印到控制台.(例如po foo()).这样做之后,我收到以下消息:
错误:执行被中断,原因:断点2.1.
该进程已在执行前返回到该状态.
但是,该功能没有断点.为什么它会向我显示此错误而不执行该功能?
这是在Xcode 4.6上.
提前感谢您提供有关我所遇到的问题的任何帮助/见解.就在最近,我的iOS应用程序因可怕的EXC_BAD_ACCESS错误而开始失败.我对SO和Google进行了大量研究,并收到了一些很好的建议,但这些帖子都没有帮助我解决我的问题.到目前为止,我知道EXC_BAD_ACCESS可能是两件事之一:
1) A pointer is now pointing to memory that was deallocated.
2) A pointer itself is corrupt.
Run Code Online (Sandbox Code Playgroud)
我阅读并按照这里,这里,这里和这里的说明进行操作.当我执行"构建并运行"时,我可以100%重现exc_bad_access.但是,当我在调试器或工具中启用NSZombie时,我永远无法重现该问题.此外,NSZombie不会在控制台中留下任何有用的信息.
我最接近确定问题的方法是在每一行代码之后放置一个NSLog,以便查看崩溃的位置.我相信它在两个截然不同的地方崩溃 - 这两个点都在返回一个单元格cellForRowAtIndexPath.下面我提供了两种方法,我认为事情正在崩溃,以及我的控制台上的错误输出.任何帮助或指导将不胜感激,谢谢!
违规方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
static NSString *CellIdentifier = @"EventDetailCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor colorWithRed:150 green:143 blue:135 alpha:1.0];
cell.textLabel.highlightedTextColor = [UIColor …Run Code Online (Sandbox Code Playgroud) 目前CoreAnimation在动画期间忽略异常,因此我的断言代码不起作用.如何让CoreAnimation在动画期间不忽略异常并停止程序执行以进行调试?
在Visual Basic中,可以使用一行代码来处理代码中的错误
"On Error Resume Next"
Run Code Online (Sandbox Code Playgroud)
Objective-C中有类似的东西吗?我的问题是我有一个"添加新单元格"添加按钮,在运行时创建一个新单元格.但是,细胞是可以重新订购的.当您尝试重新排序"添加新单元格"单元格时,我得到索引超出范围错误.如果我可以修复发生错误的错误,但是如果有错误处理程序我可以用来在出现错误时退出移动函数,那也很酷.
这是我的moveRowAtIndexPath代码:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
iProfileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate moveFromOriginal:fromIndexPath.row toNew:toIndexPath.row];
}
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (7) beyond bounds (7)'
Run Code Online (Sandbox Code Playgroud) xcode ×7
exception ×4
ios ×4
iphone ×4
objective-c ×3
cocoa ×2
debugging ×2
cocoa-touch ×1
crash ×1
llvm ×1
macos ×1
nsrange ×1
stack-trace ×1
uikit ×1
uitableview ×1
xcode4 ×1
xcode4.6 ×1