ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - Nero5023/CSVParser: A swift package for read and write CSV file
A swift package for read and write CSV file. Contribute to Nero5023/CSVParser development by creating an account on GitHub.
Visit Site

GitHub - Nero5023/CSVParser: A swift package for read and write CSV file

GitHub - Nero5023/CSVParser: A swift package for read and write CSV file

CSVParser

A swift library for fast read and write CSV file. This library supports all Apple platform and Linux.

Carthage compatible Plafrom

List to do


  • get column by string subscript
  • error
  • initialization from string
  • Convert JSON To CSV
  • Convert CSV To JSON
  • Concurrent parse

Requirements


  • Swift 4.0+

Installation


Swift Package Manager(Support Ubuntu)

If you want to use this package on Ubuntu, you shounld install with Swift Package Manager

In Package.swift file

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .Package(url: "https://github.com/Nero5023/CSVParser",
        majorVersion: 1),
    ]
)

Run command

$ swift build

Carthage

To integrate CSVParser into your Xcode project using Carthage, specify it in your Cartfile:

github "Nero5023/CSVParser" ~> 2.0.0

Run carthage update to build the framework and drag the built CSVParser.framework into your Xcode project.

Usage

Initialization

let csv = try CSVParser(filePath: "path/to/csvfile")

//catch error
do {
	let csv = try CSVParser(filePath: "path/to/csvfile")
}catch {
	// Error handing
}

// Custom delimiter
do {
	let csv = try CSVParser(filePath: "path/to/csvfile", delimiter: ";")
}catch {
	// Error handing
}

// init from elements
let csv = try CSVParser(elements: [["a", "b", "c"], ["1", "2", "3"]])

Read data

do {
	let csv = try CSVParser(filePath: "path/to/csvfile")
	// get every row in csv
	for row in csv {
        print(row) // ["first column", "sceond column", "third column"]
    }
    
    // get row by int subscript 
    csv[10] // the No.10 row
    
    // get column by string subscript
    csv["id"] // column with header key "id" 
	
}catch {
	// Error handing
}

Write data

do {
	let csv = try CSVParser(filePath: "path/to/csvfile")
	// get every row in csv
	csv[0] = ["test0", "test1", "test2"]
	csv.wirite(toFilePath: "path/to/destination/file")
	
}catch {
	// Error handing
}

Subscript

// get row by int subscript 
csv[10] // the No.10 row
    
// get column by string subscript
csv["id"] // column with header key "id" 

Get dictionary elements

for dic in csv.enumeratedWithDic() {
	print(dic) // dic is [String: String]	
}

CSV to JSON

The result json type is [{"header0": "a","header1": "b"},{"header0": "a", "header1": "b"}]

do {
	let jsonStr = try csv.toJSON()
}catch {
	// Error handing
} 

JSON to CSV string

Now only support this json type [{"header0": "a","header1": "b"},{"header0": "a", "header1": "b"}]

do {
	let csvString = try CSVParser.jsonToCSVString(jsonData: jsonData) // jsonData is the Data type ot json
}catch {
	// Error handing
} 

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory