在 iPhone 上解析我的平面文件非常痛苦,请帮助我
我正在编写一个 iPhone 应用程序,它应该从网络上解析平面文件,从平面文件创建托管对象,然后在 UITableView 中显示它们。 保存和显示没有问题,但我就是无法掌握一个好的解析器的窍门。
这就是我要解析的文件: Flat-file
AS据我所知,我无法使用 NSXMLParser 来完成此任务(因为显然没有标签)。
所以我首先尝试编写一个 NSScanner ,它应该给我带来有趣的属性 -->没有成功
现在我正在使用这种方法:
- (void) parseMemberDataWithURL: (NSString *)urlString
{
self.memberTempCounter = 1;
//Get data from web
self.downloadedText = [NSString stringWithContentsOfURL: [NSURL URLWithString: urlString] encoding:NSUTF8StringEncoding error:nil ];
memberArray = [downloadedText componentsSeparatedByString:@";"];
while (self.memberTempCounter<[memberArray count])
{
[[ExhibitorController sharedController] createExhibitorWithName:[memberArray objectAtIndex:self.memberTempCounter]
street:[memberArray objectAtIndex:self.memberTempCounter+2]
zip:[memberArray objectAtIndex:self.memberTempCounter+3]
city:[memberArray objectAtIndex:self.memberTempCounter+4]
email:[memberArray objectAtIndex:self.memberTempCounter+7]
phone:[memberArray objectAtIndex:self.memberTempCounter+5]
website:[memberArray objectAtIndex:self.memberTempCounter+8]
produktbereiche:[[memberArray objectAtIndex:self.memberTempCounter+9] componentsSeparatedByString:@","]];
self.memberTempCounter= self.memberTempCounter+13;
}
}
我正在使用memberTempCounter来识别该属性。
问题是:
- 这只在 4 次中的 3 次中起作用。应用程序崩溃的 4 次中的 1 次,我不知道为什么......
- 该方法的性能就像 1962 年大众甲壳虫一样。在我的 iPhone 3G 上解析整个数据块最多需要 3 分钟
有什么想法或者更简单的方法吗?
我将非常感激。提前致谢: -)
I am programming an iPhone App which is supposed to parse a flat-file from the web, create managed objects from the flat-file and later on should display them in an UITableView.
There are no problems with the saving and the displaying, but I just can't get the hang of a good Parser.
Thats the file I want to parse: Flat-file
AS far as I know, I can't use the NSXMLParser for this task (because obviously there are no tags).
So I at first tried to programm a NSScanner which should get me the interesting properties --> didn't work out
Now I am using this method:
- (void) parseMemberDataWithURL: (NSString *)urlString
{
self.memberTempCounter = 1;
//Get data from web
self.downloadedText = [NSString stringWithContentsOfURL: [NSURL URLWithString: urlString] encoding:NSUTF8StringEncoding error:nil ];
memberArray = [downloadedText componentsSeparatedByString:@";"];
while (self.memberTempCounter<[memberArray count])
{
[[ExhibitorController sharedController] createExhibitorWithName:[memberArray objectAtIndex:self.memberTempCounter]
street:[memberArray objectAtIndex:self.memberTempCounter+2]
zip:[memberArray objectAtIndex:self.memberTempCounter+3]
city:[memberArray objectAtIndex:self.memberTempCounter+4]
email:[memberArray objectAtIndex:self.memberTempCounter+7]
phone:[memberArray objectAtIndex:self.memberTempCounter+5]
website:[memberArray objectAtIndex:self.memberTempCounter+8]
produktbereiche:[[memberArray objectAtIndex:self.memberTempCounter+9] componentsSeparatedByString:@","]];
self.memberTempCounter= self.memberTempCounter+13;
}
}
I am using the memberTempCounter to identify the property.
The problems are:
- This only works out in like 3 of 4 times.1 of 4 times the App crashes and I have no Idea why...
- The method has a performance like a 1962 VW Beetle. Parsing the whole chunk of data takes up to 3 Minutes on my iPhone 3G
Any Ideas or a simpler way to do this?
I would be really gratefull. Thanks in advance: -)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不妨在后台进行所有解析,然后在解析信息时显示。
至于内存问题,尝试使用临时自动释放池并通过循环每 50 次左右迭代释放一次。
You might as well do all the parsing in the background, and then display as the information gets parsed.
As for memory issues, try doing temporary autorelease pools and release every 50 or so iterations through the loop.
递归下降 (LL1) 解析器非常简单,占用内存少,而且就速度而言,它们几乎与在字符中运行指针一样快。构建数据结构可能是主要的时间消耗者。
Recursive-descent (LL1) parsers are pretty simple, light on memory, and for speed they go almost as fast as you can run a pointer through characters. Building your data structure would probably be the dominant time-taker.
我终于能够解决我的性能问题。
我在另一个类中有一个方法,它为不同的参展商广告标签。因此,它首先检查标签是否已存储在数据库中,否则创建它。
随着数据库中标签集的不断增加,搜索过程花费的时间越来越长,这导致解析时间很长。
其他遇到此问题的人:请参阅苹果的性能核心数据编程指南中的“高效实现查找或创建”部分:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdImporting.html< /a>
I was finally able to fix my performance problem.
I have a method in another class, which ads Tags for the different Exhibitors. Therefore it first checks if the Tag already is stored in the database or else creates it.
With an growing Set of Tags in my database the search-process took longer and longer and this led to the long parsing time.
Anyone else having this problem: Take a look at the Performance Core Data Programming guide of apple in the "Implementing Find-or-Create Efficiently"-section:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdImporting.html