Skip to content

Commit

Permalink
Apply default swift format rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Hearst committed Sep 13, 2024
1 parent 8e2d73b commit bc33bfd
Show file tree
Hide file tree
Showing 49 changed files with 2,555 additions and 2,483 deletions.
10 changes: 0 additions & 10 deletions .swiftlint.yml

This file was deleted.

38 changes: 19 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
import PackageDescription

let package = Package(
name: "ScryfallKit",
platforms: [.macOS(.v10_13), .iOS(.v12)],
products: [
.library(
name: "ScryfallKit",
targets: ["ScryfallKit"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
name: "ScryfallKit"
),
.testTarget(
name: "ScryfallKitTests",
dependencies: ["ScryfallKit"]
)
]
name: "ScryfallKit",
platforms: [.macOS(.v10_13), .iOS(.v12)],
products: [
.library(
name: "ScryfallKit",
targets: ["ScryfallKit"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
],
targets: [
.target(
name: "ScryfallKit"
),
.testTarget(
name: "ScryfallKitTests",
dependencies: ["ScryfallKit"]
),
]
)
36 changes: 18 additions & 18 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import PackageDescription

let package = Package(
name: "ScryfallKit",
platforms: [.macOS(.v10_13), .iOS(.v12)],
products: [
.library(
name: "ScryfallKit",
targets: ["ScryfallKit"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
name: "ScryfallKit"
),
.testTarget(
name: "ScryfallKitTests",
dependencies: ["ScryfallKit"])
]
name: "ScryfallKit",
platforms: [.macOS(.v10_13), .iOS(.v12)],
products: [
.library(
name: "ScryfallKit",
targets: ["ScryfallKit"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
],
targets: [
.target(
name: "ScryfallKit"
),
.testTarget(
name: "ScryfallKitTests",
dependencies: ["ScryfallKit"]),
]
)
38 changes: 19 additions & 19 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
import PackageDescription

let package = Package(
name: "ScryfallKit",
platforms: [.macOS(.v10_13), .iOS(.v12)],
products: [
.library(
name: "ScryfallKit",
targets: ["ScryfallKit"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
name: "ScryfallKit"
),
.testTarget(
name: "ScryfallKitTests",
dependencies: ["ScryfallKit"]
)
]
name: "ScryfallKit",
platforms: [.macOS(.v10_13), .iOS(.v12)],
products: [
.library(
name: "ScryfallKit",
targets: ["ScryfallKit"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
],
targets: [
.target(
name: "ScryfallKit"
),
.testTarget(
name: "ScryfallKitTests",
dependencies: ["ScryfallKit"]
),
]
)
80 changes: 40 additions & 40 deletions SampleCode/ScryfallSearcher/ScryfallSearcher/CardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,54 @@
// CardView.swift
//

import SwiftUI
import ScryfallKit
import SwiftUI

struct CardView: View {
var card: Card

var body: some View {
VStack {
AsyncImage(url: card.getImageURL(type: .normal)) { image in
image
.resizable()
.scaledToFit()
} placeholder: {
Text(card.name)
ProgressView()
}

GroupBox {
HStack {
Text(card.name)
Spacer()
Text(card.manaCost ?? "")
}

Divider()

Text(card.oracleText ?? "")
.padding(.bottom)
Text(card.flavorText ?? "")
.italic()

if let powerAndToughness = card.powerAndToughness {
Divider()
HStack {
Spacer()
Text(powerAndToughness)
}
}
}
var card: Card

var body: some View {
VStack {
AsyncImage(url: card.getImageURL(type: .normal)) { image in
image
.resizable()
.scaledToFit()
} placeholder: {
Text(card.name)
ProgressView()
}

GroupBox {
HStack {
Text(card.name)
Spacer()
Text(card.manaCost ?? "")
}

Divider()

Text(card.oracleText ?? "")
.padding(.bottom)
Text(card.flavorText ?? "")
.italic()

if let powerAndToughness = card.powerAndToughness {
Divider()
HStack {
Spacer()
Text(powerAndToughness)
}
}
}
}
}
}

extension Card {
var powerAndToughness: String? {
guard let power, let toughness else { return nil }
return "\(power)/\(toughness)"
}
var powerAndToughness: String? {
guard let power, let toughness else { return nil }
return "\(power)/\(toughness)"
}
}

//struct SwiftUIView_Previews: PreviewProvider {
Expand Down
132 changes: 66 additions & 66 deletions SampleCode/ScryfallSearcher/ScryfallSearcher/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,86 @@
// ScryfallSearcher
//

import SwiftUI
import ScryfallKit
import SwiftUI

struct ContentView: View {
private let client = ScryfallClient()
private let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 2)
private let client = ScryfallClient()
private let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 2)

@State private var loading = false
@State private var query = ""
@State private var cards = [Card]()
@State private var error: String?
@State private var showError = false
@State private var loading = false
@State private var query = ""
@State private var cards = [Card]()
@State private var error: String?
@State private var showError = false

var body: some View {
ScrollView {
TextField("Search for Magic: the Gathering cards", text: $query)
.textFieldStyle(.roundedBorder)
.autocorrectionDisabled(true)
.textInputAutocapitalization(.never)
.onSubmit {
search(query: query)
}
var body: some View {
ScrollView {
TextField("Search for Magic: the Gathering cards", text: $query)
.textFieldStyle(.roundedBorder)
.autocorrectionDisabled(true)
.textInputAutocapitalization(.never)
.onSubmit {
search(query: query)
}

if loading {
ProgressView()
} else if cards.isEmpty {
Text("Perform a search to view cards")
} else {
LazyVGrid(columns: columns) {
ForEach(cards) { card in
AsyncImage(url: card.getImageURL(type: .normal)) { image in
image
.resizable()
.scaledToFit()
} placeholder: {
Text(card.name)
ProgressView()
}
}
}
if loading {
ProgressView()
} else if cards.isEmpty {
Text("Perform a search to view cards")
} else {
LazyVGrid(columns: columns) {
ForEach(cards) { card in
AsyncImage(url: card.getImageURL(type: .normal)) { image in
image
.resizable()
.scaledToFit()
} placeholder: {
Text(card.name)
ProgressView()
}

Spacer()
}
}
.alert("Error", isPresented: $showError, presenting: error, actions: { _ in }) { error in
Text(error)
}
.refreshable {
guard !query.isEmpty else { return }
search(query: query)
}
.padding()
}
}

private func search(query: String) {
error = nil
loading = true
Spacer()
}
.alert("Error", isPresented: $showError, presenting: error, actions: { _ in }) { error in
Text(error)
}
.refreshable {
guard !query.isEmpty else { return }
search(query: query)
}
.padding()
}

Task {
do {
let results = try await client.searchCards(query: query)
await MainActor.run {
cards = results.data
}
} catch {
await MainActor.run {
showError = true
self.error = error.localizedDescription
}
}
private func search(query: String) {
error = nil
loading = true

await MainActor.run {
loading = false
}
Task {
do {
let results = try await client.searchCards(query: query)
await MainActor.run {
cards = results.data
}
} catch {
await MainActor.run {
showError = true
self.error = error.localizedDescription
}
}

await MainActor.run {
loading = false
}
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
static var previews: some View {
ContentView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import SwiftUI

@main
struct ScryfallSearcherApp: App {
var body: some Scene {
WindowGroup {
SearchView()
}
var body: some Scene {
WindowGroup {
SearchView()
}
}
}
Loading

0 comments on commit bc33bfd

Please sign in to comment.