iOS5 NSMutableDictionary 有效转换为逗号分隔的值列表
我在一个应用程序中获得了大约 30000 行数据,我想将其添加到 CSV 文件中并通过电子邮件发送给用户。当前每个数据点都有大约 20 个属性,我将添加大约 20 个值作为扩展属性,存储在 NSMutableDictionary 中。这是大量数据,创建文件并将其附加到电子邮件已经需要约 10 秒的时间。
我可以使用常规属性构建一串 CSV 值,
[NSString stringWithFormat:@"%f,%f,%f",prop1,prop2,prop3 ];
我可以像这样迭代字典。我可以为每个键重复构建一个字符串,但这每次都会重新创建一个新字符串。 iOS 中是否有 StringBuilder 或 StringBuffer 的等效项? 将
for(NSString *aKey in myDictionary){
NSLog(aKey);
//append string
}
NSMutableDictionary 中的现有属性和扩展属性组合起来以创建单个逗号分隔值字符串的最佳方法是什么?
I got ~30000 rows of data in an app that I would like to add to a CSV file and email to the user. Each data point currently has ~20 properties and I'm adding ~20 more values as extended attributes, stored in a NSMutableDictionary. That's a lot of data, and it already takes ~10 seconds to create the file and attach it to an email.
I can build a string of CSV values from regular properties using
[NSString stringWithFormat:@"%f,%f,%f",prop1,prop2,prop3 ];
I can iterate the dictionary like this. I can repeatedly build a string for each key, but this would re-create a new string each time. Is there an equivalent of StringBuilder or StringBuffer in iOS?
for(NSString *aKey in myDictionary){
NSLog(aKey);
//append string
}
What's the best way to combine existing properties and extended attributes from an NSMutableDictionary to create a single string of comma separated values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 for 循环外部初始化一个可变字符串并根据需要附加它。
Initialize a mutable string outside the for loop and append it however you want.
这篇文章很旧,但对于任何寻找更清洁解决方案的人来说,你可以这样做:
This post is old but for anyone looking for a cleaner solution you could do this: