EXC_BAD_ACCESS错误

发布于 2024-11-30 08:26:24 字数 252 浏览 13 评论 0原文

当我运行此代码时,

NSString *string = [NSString stringWithFormat:@"http://makrr.com/*****/****/*****/****/%@.mp3", [data objectForKey:@"location"]];`  

我得到了 EXC_BAD_ACCESS。 [data objectForKey:@"Location"] 是一个 NSCFString。

When I run this code

NSString *string = [NSString stringWithFormat:@"http://makrr.com/*****/****/*****/****/%@.mp3", [data objectForKey:@"location"]];`  

Im getting a EXC_BAD_ACCESS. [data objectForKey:@"Location"] is a NSCFString.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无可置疑 2024-12-07 08:26:24

我不确定 EXC_BAD_ACCESS 来自哪里,但编译器正在将 [data objectForKey:@"Location"] 读取为 NSCFString,因为 NSString 是一个类簇,以及其他 Foundation 类型,例如 NSNumber 和 NSArray:

类簇是 Foundation 框架的一种设计模式
广泛使用。班级集群分组了一些私人、
公共抽象超类下的具体子类。分组情况
以这种方式的类简化了公开可见的架构
一个面向对象的框架,同时又不降低其功能的丰富性。
类簇基于抽象工厂设计模式
在“Cocoa 设计模式”中讨论过。

最有可能的是,[data objectForKey:@"Location"] 已被释放过多次并已被释放。这可能会出现错误 EXC_BAD_ACCESS。您应该仔细检查内存管理以确保它没有被自动释放(或手动释放)。

I'm not sure where the EXC_BAD_ACCESS is coming from, but the compiler is reading [data objectForKey:@"Location"] as an NSCFString since NSString is a class cluster, along with other Foundation types such as NSNumber and NSArray:

Class clusters are a design pattern that the Foundation framework
makes extensive use of. Class clusters group a number of private,
concrete subclasses under a public, abstract superclass. The grouping
of classes in this way simplifies the publicly visible architecture of
an object-oriented framework without reducing its functional richness.
Class clusters are based on the Abstract Factory design pattern
discussed in “Cocoa Design Patterns.”

Most likely, [data objectForKey:@"Location"] has been released one too many times and has been deallocated. This could case an error EXC_BAD_ACCESS. You should check your memory management carefully to see that it is not being autoreleased (or manually released).

少女情怀诗 2024-12-07 08:26:24

EXC_BAD_ACCESS 表示您正在尝试访问已从内存中释放的数据。最有可能的是,您忘记在途中的某个地方保留 data 对象,或者关键“位置”的对象被释放了太多次。如果没有更多上下文代码,很难准确判断问题出在哪里。

这是一个问题,其中的一些答案很好地解释了 EXC_BAD_ACCESS.

EXC_BAD_ACCESS means you're trying to access data that has been freed from memory. Most likely, you forgot to retain your data object somewhere along the way, or the object for the key "location" was released too many times. It's hard to tell exactly what the problem is without more code for context.

Here's a question with a few answers that provide good explanations of EXC_BAD_ACCESS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文