Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there anyway to write data into array #44

Open
MatinC opened this issue Nov 6, 2017 · 1 comment
Open

Is there anyway to write data into array #44

MatinC opened this issue Nov 6, 2017 · 1 comment

Comments

@MatinC
Copy link

MatinC commented Nov 6, 2017

I trying to add each row automatically by running for-loop but it keep telling me index out of range there

` let itemList = objectNo
let fileManager = FileManager.default

    let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
    csvFile = documentDirectory.appendingPathComponent("\(fileName!).csv")
    let path = csvFile
    
    let stream = OutputStream(url: csvFile!, append: false)
    let csv = try! [CSVWriter(stream: stream!)]
    try! csv[0].write(row: ["name", "x", "y", "width", "height"])
    
    for no in 0..<itemList.count - 1 {
        try! csv[no].write(row: [String(describing: objects.dataName[no]), String(describing: objects.dataX[no]), String(describing: objects.dataY[no]), String(describing: objects.boundingX[no]), String(describing: objects.boundingY[no])])
    }
    csv[itemList.count].stream.close()`
@jsubida
Copy link

jsubida commented Aug 21, 2022

I'm assuming the issue is with the following line

csv[itemList.count].stream.close()

I'm not sure if the number of items in itemList equals the number of items in csv, but if this is true, then this would be the reason your code is crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants