For example I have a list of some items in a text file. I want to read that data one by one. How can I do that in Swift? I've found NSString.stringWithContentsOfFile(path)
but this reads whole file. In C++ i was using ifstream for that. Example:
ifstream fd(fileName);
string code, type, title;
int price, date;
getline(fd, title);
while (!fd.eof()) {
getline(fd, code, ',');
fd >> ws;
getline(fd, type, ',');
fd >> ws;
fd >> date;
fd.ignore();
fd >> price;
fd.ignore();
}
fd.close();
And sample text file for that:
Title of List
K123, document, 1994, 12500
S156, photo, 2006, 7000
R421, book, 1998, 6000
How can I read files with Swift like that and get words in it one by one?