加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 枚举包含字典的数组会产生意外的输出

发布时间:2020-12-16 06:48:37 所属栏目:百科 来源:网络整理
导读:我的问题是为什么它会输出日志中的最后4行(见下文)……这些对象是日志和早先在日志中打印的字典的一部分.不应该位于数组的末尾?我在这里缺少一些基本的东西…… thx NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSURL URLWit
我的问题是为什么它会输出日志中的最后4行(见下文)……这些对象是日志和早先在日志中打印的字典的一部分.不应该位于数组的末尾?我在这里缺少一些基本的东西…… thx

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSURL URLWithString: @"www.stanford.edu"],@"Stanford University",[NSURL URLWithString: @"www.apple.com"],@"Apple shop",[NSURL URLWithString: @"cs193p.stanford.edu"],@"CS193P course",[NSURL URLWithString: @"itunes.stanford.edu"],@"Stanford on iTunes U",[NSURL URLWithString: @"stanfordshop.com"],@"Stanford Mall",nil];

NSMutableArray *myArray = [NSMutableArray arrayWithObjects:
    [NSString init],[NSURL URLWithString: @"www.stanford.edu"],[NSProcessInfo processInfo],dictionary,[@"Mutable string example" mutableCopy],[@"another mutable string" mutableCopy]];

NSEnumerator *enumerator = [myArray objectEnumerator];
id object;

while ((object = [enumerator nextObject])) {
    NSLog([object description]);
}

2009-07-02 09:35:12.756 WhatATool [6407:10b] NSString
2009-07-02 09:35:12.756 WhatATool [6407:10b] www.stanford.edu
2009-07-02 09:35:12.757 WhatATool [6407:10b]< NSProcessInfo:0x107e20>
2009-07-02 09:35:12.758 WhatATool [6407:10b] {
????“Apple shop”= www.apple.com;
????“CS193P课程”= cs193p.stanford.edu;
????“斯坦福购物中心”= stanfordshop.com;
????“斯坦福大学”= www.stanford.edu;
????“斯坦福在iTunes U上”= itunes.stanford.edu;
}
2009-07-02 09:35:12.758 WhatATool [6407:10b]可变字符串示例
2009-07-02 09:35:12.759 WhatATool [6407:10b]另一个可变字符串
2009-07-02 09:35:12.760 WhatATool [6407:10b] itunes.stanford.edu
2009-07-02 09:35:12.760 WhatATool [6407:10b]斯坦福在iTunes U上
2009-07-02 09:35:12.761 WhatATool [6407:10b] stanfordshop.com
2009-07-02 09:35:12.762 WhatATool [6407:10b]斯坦福购物中心

解决方法

当你使用方法创建NSMutableArray时,我认为你缺少必要的nil作为最后一个参数.是否

NSMutableArray *myArray = [NSMutableArray arrayWithObjects:
    [NSString init],[@"another mutable string" mutableCopy],nil];

工作?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读