Skip to content

Commit

Permalink
Update README.md (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
fummicc1 authored Feb 1, 2023
1 parent ca42f36 commit 1d0f5fa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ A helper library to generate `Csv` in Csv2Img library.

## How to use

1. Define custom type which conform to `CsvComposition`.
1. Define custom type that conforms to `CsvComposition`.

```swift
import Foundation
import Csv2Img


public struct ExampleComposition: CsvComposition {
public struct CsvCompositionExample: CsvComposition {
@CsvRows(column: "age")
public var ages: [String]

Expand All @@ -135,12 +135,21 @@ public struct ExampleComposition: CsvComposition {
2. Build `Csv`

```swift
let composition: ExampleComposition = .init()
let composition: CsvCompositionExample = .init()
composition.ages.append(contentsOf: ["98", "99", "100"])
composition.names.append(contentsOf: ["Yamada", "Tanaka", "Sato"])
let csv = try! composition.build()
```

or you can write different way like the below.

```swift
let yamada = Csv.Row(index: 0, values: ["98", "Yamada"])
let tanaka = Csv.Row(index: 1, values: ["99", "Tanaka"])
let sato = Csv.Row(index: 2, values: ["100", "Sato"])
let csv = try! CsvCompositionParser.parse(type: CsvCompositionExample.self, rows: [yamada, tanaka, sato,])
```

| Result |
| ------ |
|<img width="392" alt="スクリーンショット 2022-08-26 12 54 22" src="https://user-images.githubusercontent.com/44002126/186814170-0c33013e-c138-4ed5-a34c-5d45dc8ac0c0.png">|
Expand Down

0 comments on commit 1d0f5fa

Please sign in to comment.