“超出范围”迭代 NSMutableArray 时出错

发布于 2024-09-02 02:36:06 字数 354 浏览 14 评论 0原文

为什么每当我尝试访问此循环中的“url”变量时,都会收到“超出范围”错误?

for(NSString *url in self.winnerImageURLs) {
        [mediaItemString appendFormat:@"{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"},", url, url];
    }

“self.winnerImageURLs”NSMutableArray 中的每个项目的类都以 NSCFString 的形式返回,所以我不确定这里的处理是什么。

关于我做错了什么有什么想法吗???

谢谢

Why am I getting an "out of scope" error whenever I try to access the "url" variable in this loop?

for(NSString *url in self.winnerImageURLs) {
        [mediaItemString appendFormat:@"{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"},", url, url];
    }

The class of very item in the "self.winnerImageURLs" NSMutableArray comes back as NSCFString so I'm not sure what the dealio is here.

Any ideas on what I'm doing wrong???

Thanks

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

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

发布评论

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

评论(2

夜巴黎 2024-09-09 02:36:06

如果您谈论的是在调试器中访问 url 变量,这种情况会发生很多。这本身不是问题。

If you're talking about accessing the url variable in the debugger, it happens quite a lot. It's not a problem in itself.

煞人兵器 2024-09-09 02:36:06

简短的回答是它应该是这样的。更长的答案是 NSString 是一个类簇。

类簇

类簇是一种架构
该团体有许多私人,
public下的具体子类,
抽象超类。的分组为
以这种方式提供的类提供了
简化的用户界面
只看到公开可见的
建筑学。在幕后,
不过,抽象类正在调用
最适合的私有子类
用于执行特定任务。

许多常见的 Cocoa 类都是作为类簇实现的,包括 NSArray、NSString 和 NSDictionary。

您可以像创建任何其他类一样创建集群实例并与之交互。然而,在幕后,当您创建公共类的实例时,该类会根据您调用的创建方法返回适当子类的对象。 (你不会,也不能选择实例的实际类。)

NSString 示例

NSString *a = @"UTF32.txt";

NSString *b = [NSHomeDirectory() stringByAppendingPathComponent:a];

NSTextStorage *storage = [[NSTextStorage alloc] initWithString:b];

NSString *c = [storage string];

a、b 和 c 中的每一个都可能是(在 10.5 中是)不同私有的实例子类(事实上,在 Mac OS X v10.5 上,每个都是)。尽管每个对象都是 NSString 的私有子类,但将每个对象视为 NSString 类的实例是很方便的。

关于Apple开发者站点中的类簇http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref /doc/uid/TP40002974-CH4-SW34

Short anwer is that it is supposed to be like that. A longer answer is that NSString is a class cluster.

Class cluster

A class cluster is an architecture
that groups a number of private,
concrete subclasses under a public,
abstract superclass. The grouping of
classes in this way provides a
simplified interface to the user, who
sees only the publicly visible
architecture. Behind the scenes,
though, the abstract class is calling
up the private subclass most suited
for performing a particular task.

Many common Cocoa classes are implemented as class clusters, including NSArray, NSString, and NSDictionary.

You create and interact with instances of the cluster just as you would any other class. Behind the scenes, though, when you create an instance of the public class, the class returns an object of the appropriate subclass based on the creation method that you invoke. (You don’t, and can’t, choose the actual class of the instance.)

NSString example

NSString *a = @"UTF32.txt";

NSString *b = [NSHomeDirectory() stringByAppendingPathComponent:a];

NSTextStorage *storage = [[NSTextStorage alloc] initWithString:b];

NSString *c = [storage string];

Each of a,b and c may be (and in 10.5 is) an instance of a different private subclass (and in fact, on Mac OS X v10.5, each is). Although each of the objects is of a private subclass of NSString, it’s convenient to consider each of the objects to be instances of the NSString class.

About Class Clusters in Apple Developer site: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW34

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