简体   繁体   English

使用NSUserDefaults保存NSMutableArray

[英]Save NSMutableArray with NSUserDefaults

i'm french so maybe i'll make some mistakes, sorry about that :D 我是法国人,所以也许我会犯一些错误,对此感到抱歉:D

I explain my problem, I have a XMLParser who generates NSString (title, category, url, ...), I would like the stream that is generated is to save the user can read the stream even if it is not connected to the internet. 我解释了我的问题,我有一个生成NSString(标题,类别,URL,...)的XMLParser,我希望生成的流是为了保存用户即使未连接到互联网也可以读取该流。

The flow generated can be found here ==> http://www.recontv.fr/testXml.xml 生成的流可以在这里找到==> http://www.recontv.fr/testXml.xml

I try different solutions and each time, I should go about it wrong but its not working. 我尝试不同的解决方案,并且每次都应该解决这个问题,但是它不起作用。 : ( :(

Do you need my code? 您需要我的代码吗? Did I explain my problem? 我有解释我的问题吗?

Thank you in advance for your help! 预先感谢您的帮助!

PS: I post on differents forum for a answer, if I take it somewhere else, i pick here too. PS:我在“差异论坛”上发布了答案,如果我将其放在其他地方,我也会在此处选择。

NSUserDefaults isn't really meant to be used for saving an array from XML to it. NSUserDefaults并不是真正用于将数组从XML保存到它。 Your main solutions are to save the XML to a file and re-parse when the user needs to access the information offline, or you can save the NSArray itself to a file using either its writeToFile: methods, or NSKeyedArchiver/NSKeyedUnarchiver. 您的主要解决方案是将XML保存到文件中,并在用户需要脱机访问信息时重新解析,或者可以使用其writeToFile:方法或NSKeyedArchiver / NSKeyedUnarchiver将NSArray自身保存到文件中。 In each case you must ensure that the objects in your array conform to the NSCoding protocol. 在每种情况下,您都必须确保阵列中的对象符合NSCoding协议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM