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.
31 lines
768 B
Swift
31 lines
768 B
Swift
5 years ago
|
//
|
||
|
// Description.swift
|
||
|
// SwiftCSV
|
||
|
//
|
||
|
// Created by Will Richardson on 11/04/16.
|
||
|
// Copyright © 2016 Naoto Kaneko. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
extension CSV: CustomStringConvertible {
|
||
|
public var description: String {
|
||
|
let head = header.joined(separator: ",") + "\n"
|
||
|
let cont = namedRows.map { row in
|
||
|
return header.map { key -> String in
|
||
|
let value = row[key]!
|
||
|
|
||
|
// Add quotes if value contains a comma
|
||
|
if value.contains(",") {
|
||
|
return "\"\(value)\""
|
||
|
}
|
||
|
return value
|
||
|
|
||
|
}.joined(separator: ",")
|
||
|
|
||
|
}.joined(separator: "\n")
|
||
|
return head + cont
|
||
|
}
|
||
|
}
|
||
|
|