Slide 1

Slide 1 text

.app jq

Slide 2

Slide 2 text

id:cockscomb

Slide 3

Slide 3 text

jq

Slide 4

Slide 4 text

jq stedolan.github.io/jq/ $ echo '{"foo": "bar"}' | jq '.foo' "bar"

Slide 5

Slide 5 text

gh Scripting with GitHub CLI | The GitHub Blog $ gh api ... -- jq '.[].login' # = > "user1" # = > "user2" # = > ...

Slide 6

Slide 6 text

jq JSON

Slide 7

Slide 7 text

.app

Slide 8

Slide 8 text

URL

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

jq

Slide 11

Slide 11 text

Swift jq

Slide 12

Slide 12 text

gojq itchyny/gojq: Pure Go implementation of jq

Slide 13

Slide 13 text

golang.org/x/mobile

Slide 14

Slide 14 text

package binding import ( "github.com/itchyny/gojq" _ "golang.org/x/mobile/bind" ) type Query struct { query *gojq.Query } func NewQuery(src string) (*Query, error) { query, err := gojq.Parse(src) if err != nil { return nil, err } return &Query{query: query}, nil } func (q *Query) Run(input []byte) (*Iterator, error) { ... }

Slide 15

Slide 15 text

$ gomobile bind \ -target=ios,iossimulator,macos,maccatalyst \ -iosversion 14 \ -prefix GOJQ \ -o Frameworks/GOJQBinding.xcframework \ github.com/cockscomb/swift-gojq/binding

Slide 16

Slide 16 text

import Foundation open class GOJQBindingIterator : NSObject, goSeqRefInterface { public init() open func next() throws -> Data } open class GOJQBindingQuery : NSObject, goSeqRefInterface { public init?(_ src: String?) open func run(_ input: Data?) throws -> GOJQBindingIterator } public func GOJQBindingNewQuery(_ src: String?, _ error: NSErrorPointer) -> GOJQBindingQuery?

Slide 17

Slide 17 text

import GOJQBinding enum QueryError: Error { case unknown } public struct Query { private let binding: GOJQBindingQuery public init(_ query: String) throws { var error: NSError? guard let binding = GOJQBindingNewQuery(query, &error) else { throw error ?? QueryError.unknown } self.binding = binding } public func run(_ input: Data) throws -> AsyncThrowingStream { ... } }

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

// swift-tools-version: 5.7 import PackageDescription let package = Package( name: "SwiftGoJq", platforms: [ .macOS(.v13), .macCatalyst(.v14), .iOS(.v14) ], products: [ .library(name: “SwiftGoJq”, targets: ["SwiftGoJq"]), ], dependencies: [], targets: [ .binaryTarget( name: "GOJQBinding", url: "https://github.com/cockscomb/swift-gojq/releases/download/0.1.0/ GOJQBinding.xcframework.zip", checksum: "1c45710de17fb7020dcfc75105344729725c5e3875e7058e98790e5f4e178162"), .target( name: "SwiftGoJq", dependencies: [ "GOJQBinding", ]), ] )

Slide 20

Slide 20 text

cockscomb/swift-gojq

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

import AppIntents import AsyncAlgorithms import SwiftGoJq struct JQIntent: AppIntent { static var title: LocalizedStringResource = "jq" @Parameter(title: "JSON") var input: String @Parameter(title: "Query") var query: String static var parameterSummary: some ParameterSummary { Summary("\(\.$input) | jq '\(\.$query)'") } func perform() async throws -> some IntentResult { let jq = try Query(query) let results = try jq.run(input) let array = try await Array(results) return .result(value: array) } }

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

WEB+DB PRESS vol. 1 3 2 iOS 1 6 12/24 3 id:cockscomb id:yutailang 01 19 id:kouki_dan