Berkehan Atikeler Berkehan Atikeler - 16 days ago 8
Swift Question

Swift CSVImporter Cannot use instance member path within property

I am currently trying to import a CSV file using CSVImporter. The github repo says that it is up to date with the current Swift version 3.0. However I am getting an error which I couldn't find a solution to on the internet.

This is the error:

This is the github repo:

I would gladly provide anymore information if needed.

hnh hnh

These errors are unrelated to the CSVImporter library.

The first error happens because you are referring one ivar from another. Essentially this is not valid in Swift:

class ABC {
  let hello = "Hello"
  let hello_world = hello + " World" // references 'hello'

The second error happens because you directly put code into your class. Code in Swift lives in methods or in initialisers, but not directly in a class.

I think this may be what you want:

class ViewController {

  let path = "/tmp/blub.csv"

  func load() {
    let importer = CSVImporter<[String]>(path: path)
    importer.startImportingRecords ... {

And if this is part of a VC (e.g. you might want to display the CSV in a tableview), you probably want to load the data off the main queue, not in init().

P.S.: Do not only send image links to source code. Copy/paste the relevant source code into the question.