Swift和CSVImporter:仅导入.csv的第一行

时间:2019-05-28 20:39:50

标签: swift csv

我正在尝试导入一个csv并使用CSVImporter对其进行解析。但是,当我打印对象数组的计数时,它仅导入20行中的1行。

我尝试使用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...)
                }

控制台中打印的CSV中的前3个条目(“社会学,经济学和人类学”,“心理学和教育”以及“护理”)

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, bnull@mail.edu, 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/

1 个答案:

答案 0 :(得分:1)

仅使用CSwiftV而不是CSVImporter解决了该问题。 https://github.com/Daniel1of1/CSwiftV