-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update csv builder with swift-syntax (#38)
* Remove example of CsvComposition from public API * Add `CsvCompositionParser` * Add comment * Add txt file
- Loading branch information
Showing
15 changed files
with
317 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Examples/CsvBuilderExample/CsvBuilderExample/CsvCompositionExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import CsvBuilder | ||
|
||
struct CsvCompositionExample: CsvComposition { | ||
@CsvRows(column: "age") | ||
var ages: [String] | ||
|
||
@CsvRows(column: "name") | ||
var names: [String] | ||
|
||
init() { } | ||
} |
11 changes: 11 additions & 0 deletions
11
Examples/CsvBuilderExample/CsvBuilderExample/CsvCompositionExample.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import CsvBuilder | ||
|
||
struct CsvCompositionExample: CsvComposition { | ||
@CsvRows(column: "age") | ||
var ages: [String] | ||
|
||
@CsvRows(column: "name") | ||
var names: [String] | ||
|
||
init() { } | ||
} |
38 changes: 38 additions & 0 deletions
38
Examples/CsvBuilderExample/CsvBuilderExample/SecondContentView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import SwiftUI | ||
import Csv2Img | ||
import CsvBuilder | ||
|
||
|
||
struct SecondContentView: View { | ||
@State private var composition: CsvCompositionExample = .init() | ||
@State private var image: CGImage? | ||
|
||
var body: some View { | ||
VStack { | ||
Image(systemName: "globe") | ||
.imageScale(.large) | ||
.foregroundColor(.accentColor) | ||
Text("Hello, world!") | ||
if let image = image { | ||
Image(nsImage: NSImage(cgImage: image, size: CGSize(width: image.width, height: image.height))) | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
} | ||
} | ||
.padding() | ||
.task { | ||
let yamada = Csv.Row(index: 0, values: ["98", "Yamada"]) | ||
let tanaka = Csv.Row(index: 0, values: ["99", "Tanaka"]) | ||
let sato = Csv.Row(index: 0, values: ["100", "Sato"]) | ||
let csv = try! CsvCompositionParser.parse(type: CsvCompositionExample.self, rows: [yamada, tanaka, sato,]) | ||
let data = try! await csv.generate(fontSize: 20, exportType: .png) | ||
self.image = data.base as! CGImage | ||
} | ||
} | ||
} | ||
|
||
struct SecondContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SecondContentView() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.