Here is a sample of my CSV
这是我的CSV示例
10820 0 0 0 0
10900 2 4 4 4
11000 21 50 54 58
11100 23 54 59 63
11200 25 59 63 68
11300 27 63 68 73
11400 29 68 73 78
11500 31 72 78 83
11600 32 76 82 88
11700 34 81 87 93
I'm looking to create to use xcode to retreive one line of code from this very lengthy CSV based on the first line.
我希望创建使用xcode从基于第一行的这个非常冗长的CSV中检索一行代码。
For example:
- if the user enters "10900", the second line columns will be returned.
- If the user returns 11650, the 11600 line columns will be returned...always taking the lower line when the input value is less then the following line.
如果用户输入“10900”,将返回第二行列。
如果用户返回11650,则将返回11600行列...当输入值小于下一行时,始终采用较低的行。
Any help would be appreciated. I've seen code to parse an entire CSV file, but I'm thinking this may be a big memory drain, right now my CSV has 2000 lines of values, which are all in ascending order based on the first column.
任何帮助,将不胜感激。我已经看到了解析整个CSV文件的代码,但我认为这可能是一个很大的内存消耗,现在我的CSV有2000行值,它们都是基于第一列的升序。
1 个解决方案
#1
0
You have to load a file into memory anyways to find correct value.
您必须将文件加载到内存中才能找到正确的值。
With such a big CSV file I would recommend to turn CSV file into binary file (plist file for example) and put it as binary into your application - instead of parsing it each time in RunTime. It has much better performance and it's easier to work with that since you are working directly with NSDictonaries an NSArrays.
有了这么大的CSV文件,我建议将CSV文件转换为二进制文件(例如plist文件)并将其作为二进制文件放入应用程序中 - 而不是每次在RunTime中解析它。它具有更好的性能,并且更容易使用它,因为您直接使用NSDictonaries和NSArrays。
If you don't want to do it for some reason, the next solution is to use something like CHCSVParser: https://github.com/davedelong/CHCSVParser
如果您不想出于某种原因这样做,下一个解决方案是使用类似CHCSVParser的东西:https://github.com/davedelong/CHCSVParser
It provides optimization for loading only part of file at a time - which is the optimization you might be looking for.
它提供了一次只加载部分文件的优化 - 这是您可能正在寻找的优化。
#1
0
You have to load a file into memory anyways to find correct value.
您必须将文件加载到内存中才能找到正确的值。
With such a big CSV file I would recommend to turn CSV file into binary file (plist file for example) and put it as binary into your application - instead of parsing it each time in RunTime. It has much better performance and it's easier to work with that since you are working directly with NSDictonaries an NSArrays.
有了这么大的CSV文件,我建议将CSV文件转换为二进制文件(例如plist文件)并将其作为二进制文件放入应用程序中 - 而不是每次在RunTime中解析它。它具有更好的性能,并且更容易使用它,因为您直接使用NSDictonaries和NSArrays。
If you don't want to do it for some reason, the next solution is to use something like CHCSVParser: https://github.com/davedelong/CHCSVParser
如果您不想出于某种原因这样做,下一个解决方案是使用类似CHCSVParser的东西:https://github.com/davedelong/CHCSVParser
It provides optimization for loading only part of file at a time - which is the optimization you might be looking for.
它提供了一次只加载部分文件的优化 - 这是您可能正在寻找的优化。