“超出范围”迭代 NSMutableArray 时出错
为什么每当我尝试访问此循环中的“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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您谈论的是在调试器中访问 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.
简短的回答是它应该是这样的。更长的答案是 NSString 是一个类簇。
类簇
许多常见的 Cocoa 类都是作为类簇实现的,包括 NSArray、NSString 和 NSDictionary。
您可以像创建任何其他类一样创建集群实例并与之交互。然而,在幕后,当您创建公共类的实例时,该类会根据您调用的创建方法返回适当子类的对象。 (你不会,也不能选择实例的实际类。)
NSString 示例
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
Many common
Cocoa
classes are implemented as class clusters, includingNSArray
,NSString
, andNSDictionary
.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
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 theNSString
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