mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
Swift
44 lines
1.1 KiB
Swift
5 years ago
|
//
|
||
|
// EnumeratedView.swift
|
||
|
// SwiftCSV
|
||
|
//
|
||
|
// Created by Christian Tietze on 25/10/16.
|
||
|
// Copyright © 2016 Naoto Kaneko. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
public struct EnumeratedView: View {
|
||
|
|
||
|
public struct Column {
|
||
|
public let header: String
|
||
|
public let rows: [String]
|
||
|
}
|
||
|
|
||
|
public private(set) var rows: [[String]]
|
||
|
public private(set) var columns: [Column]
|
||
|
|
||
|
public init(header: [String], text: String, delimiter: Character, limitTo: Int? = nil, loadColumns: Bool = false) throws {
|
||
|
|
||
|
var rows = [[String]]()
|
||
|
var columns: [EnumeratedView.Column] = []
|
||
|
|
||
|
try Parser.enumerateAsArray(text: text, delimiter: delimiter, limitTo: limitTo, startAt: 1) { fields in
|
||
|
rows.append(fields)
|
||
|
}
|
||
|
|
||
|
if loadColumns {
|
||
|
columns = header.enumerated().map { (index: Int, header: String) -> EnumeratedView.Column in
|
||
|
|
||
|
return EnumeratedView.Column(
|
||
|
header: header,
|
||
|
rows: rows.map { $0[index] })
|
||
|
}
|
||
|
}
|
||
|
|
||
|
self.rows = rows
|
||
|
self.columns = columns
|
||
|
}
|
||
|
|
||
|
}
|