Я пытаюсь импортировать csv и анализировать его с помощью CSVImporter. Однако, когда я печатаю количество массива объектов, он импортирует только 1 из 20 строк.
Я пробовал использовать метод «Структура заголовка» из примера CSVImporter, но это дает мне ту же проблему. Я думаю, что это может быть как-то связано с самим CSV, и, возможно, специальные символы его портят, но я никак не могу изменить CSV.
let path = Bundle.main.path(forResource: "Departments", ofType: "csv")
let importer = CSVImporter<Department>(path: path!)
importer.startImportingRecords { recordValues -> Department in
return Department(name: recordValues[0], advisingInfo: recordValues[1], calendar: recordValues[2], chair: recordValues[3], icon: recordValues[4], office: recordValues[5], summary: recordValues[6], tutorLink: recordValues[7], url: recordValues[8])
}.onFinish { importedRecords in
for dept in importedRecords {
// Now importedRecords is an array of Departments
print(importedRecords.count) // returns 1 which is the first department (Sociology...)
}
Первые 3 записи в формате CSV, распечатанные в консоли («Социология, экономика и антропология», «Психология и образование» и «Сестринское дело»)
Name,AdvisingInfo,Calendar,Chair,Icon,Office,Summary,TutorLink,URL,ChairPhone,AdvismentLink
"Sociology, Economics and Anthropology",You have chosen a major in the Sociology,,Dr. Jill Null,ic_soc,Null Hall NH 200,"The Department of Sociology, Economics and Anthropology offers a
rich variety of sociology, anthropology, economics, geography, and
human services courses. The department offers courses that are
required in many of the degree programs at County College of
Null, including the Liberal Arts and Business degree. The
department's experienced faculty members have a broad range of
interests and expertise, as reflected in the many electives available
in the department.",,https://www.null.edu/,973-555-5610,https://www.null.edu/student-life/
Psychology and Education,"You have chosen a major in the Psychology and Education
Department.
As a full-time student you must meet with an Academic Advisor
to receive advisement clearance before registering for classes
each semester. As a part-time student you are encouraged to
meet with an Academic Advisor on a regular basis (although
clearance to register is not necessary). In order to build a
relationship and have continuity in your educational planning, it
is advisable to meet with the same faculty member each
semester for advisement.
For students majoring in Humanities Social Sciences/Liberal Arts
(P1130), contact the office of the Dean of Liberal Arts, Dr Bob
Null, Cohen Hall 253, [email protected], 973-555-5555, and you
will be referred to a specific faculty member(s) for academic
advisement.
Registration for the spring and fall semesters begins in early
November and April, respectively. Be on the look out for more
information about ""Advisement Week"" for your department/
major.",,Josh Null,ic_psych,Null Hall NH 200,"The Department of Psychology and Education is a member of the
Division of Liberal Arts. It is comprised of courses and programs in
(a) psychology, (b) early childhood education and (c) teacher
education. The department supports the liberal arts curriculum and
the college’s overall mission to provide students with transferable
liberal arts courses, courses to fulfill the general education
requirements in numerous curricula, providing a comprehensive
background in the behavioral sciences.",,https://www.null.edu/academics/,973-555-5555,https://www.null.edu/student-life/
Nursing,"Academic Advisors are available to help you select the courses that
best support your educational and career goals as well as provide
direction to the many resources and support services available at
the college. Each semester, full-time students pursuing a degree at
CCM must see their Academic Advisor(s) to obtain advisement
clearance in order to register for classes.",,Dr. K. Lucy Null,ic_nursing,Null Hall NH 300,"The Nursing program is fully accredited by the Accreditation
Commission for Education in Nursing. Graduates of the program are
granted an Associate in Applied Science degree and have attained
the academic requirements to apply for the National Council
Licensing Examination (NCLEX) and Registered Nurse Licensure.
The program offers a balance of general education and nursing
courses to prepare students for Registered Nurse positions.",http://www.null.edu/academics/,https://www.null.edu/academics,973-555-5555,https://www.null.edu/
Исправлена проблема, просто используя CSwiftV вместо CSVImporter. https://github.com/Daniel1of1/CSwiftV