質問

I'm importing data from .csv-files and would like to show a progress indicator, therefore I need to know how many rows exist.

Is there a performant way to achieve this, similar to wc -l filename.csv in the terminal?

役に立ちましたか?

解決

Actually you do not need to know how many rows are in your file. You just need the filesize: unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:someFilePath error:nil] fileSize];

Then just divide it by the size of the characters per line (not to mention that all rows need to have the same amount of chars)

EDIT: alternatively you could go with the amount of processed chars.

actually even wc is reading the file first. if you do not want to read the file completely in the first place, i think this is the only way to go.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top