Skip to content

Commit

Permalink
feat(Example): Run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkrouk committed May 7, 2021
1 parent 26dbb17 commit 581fab9
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 117 deletions.
6 changes: 3 additions & 3 deletions Example/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let package = Package(
name: "SPMGenExample",
platforms: [
.macOS(.v10_15),
.iOS(.v13)
.iOS(.v13),
],
products: [
.library(
Expand All @@ -33,12 +33,12 @@ let package = Package(
.product(
name: "SPMResources",
package: "spmgen"
)
),
],
resources: [
.process("Resources")
]
),
.target(name: "SPMGenExampleCore")
.target(name: "SPMGenExampleCore"),
]
)
6 changes: 3 additions & 3 deletions Example/Shared/SPMGenExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import SPMGenExampleApp
import SwiftUI

#if os(iOS)
public typealias CocoaApplicationDelegateAdaptor = UIApplicationDelegateAdaptor
public typealias CocoaApplicationDelegateAdaptor = UIApplicationDelegateAdaptor
#elseif os(macOS)
public typealias CocoaApplicationDelegateAdaptor = NSApplicationDelegateAdaptor
public typealias CocoaApplicationDelegateAdaptor = NSApplicationDelegateAdaptor
#endif

@main
struct SPMGenExampleApp: App {
@CocoaApplicationDelegateAdaptor
var appDelegate: AppDelegate

var body: some Scene {
WindowGroup {
ContentView()
Expand Down
39 changes: 18 additions & 21 deletions Example/Sources/SPMGenExampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import SPMGenExampleResources

#if os(iOS)
import UIKit
public typealias CocoaApplication = UIApplication
public typealias CocoaApplicationDelegate = UIApplicationDelegate
import UIKit
public typealias CocoaApplication = UIApplication
public typealias CocoaApplicationDelegate = UIApplicationDelegate

public final class AppDelegate: NSObject, CocoaApplicationDelegate {
public func application(
_ application: CocoaApplication,
didFinishLaunchingWithOptions launchOptions: [
CocoaApplication.LaunchOptionsKey : Any
]? = nil
) -> Bool {
CocoaFont.bootstrap()
return true
public final class AppDelegate: NSObject, CocoaApplicationDelegate {
public func application(
_ application: CocoaApplication,
didFinishLaunchingWithOptions launchOptions: [CocoaApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
CocoaFont.bootstrap()
return true
}
}
}
#elseif os(macOS)
import AppKit
public typealias CocoaApplication = NSApplication
public typealias CocoaApplicationDelegate = NSApplicationDelegate
import AppKit
public typealias CocoaApplication = NSApplication
public typealias CocoaApplicationDelegate = NSApplicationDelegate

public final class AppDelegate: NSObject, CocoaApplicationDelegate {
public func applicationDidFinishLaunching(_ notification: Notification) {
CocoaFont.bootstrap()
public final class AppDelegate: NSObject, CocoaApplicationDelegate {
public func applicationDidFinishLaunching(_ notification: Notification) {
CocoaFont.bootstrap()
}
}
}
#endif

80 changes: 41 additions & 39 deletions Example/Sources/SPMGenExampleApp/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import SwiftUI
import SPMGenExampleResources
import SwiftUI

public struct ContentView: View {
public init() {}

public var body: some View {
NavigationView {
#if os(iOS)
Expand All @@ -23,32 +23,32 @@ public struct ContentView: View {
)
)
#elseif os(macOS)
List {
NavigationLink(
"Image",
destination: imageContent()
)
NavigationLink(
"Color",
destination: colorContent()
)
NavigationLink(
"Fonts",
destination: List {
systemFontsContent()
customFontsContent()
}
)
}
List {
NavigationLink(
"Image",
destination: imageContent()
)
NavigationLink(
"Color",
destination: colorContent()
)
NavigationLink(
"Fonts",
destination: List {
systemFontsContent()
customFontsContent()
}
)
}
#endif
}
}

private func systemFontsContent() -> some View {
let fontWeights: [Font.Weight] = [
.ultraLight, .thin, .light,
.regular, .medium, .semibold,
.bold, .heavy, .black
.bold, .heavy, .black,
]
return Section(header: Text("System")) {
ForEach(fontWeights, id: \.self) { fontWeight in
Expand All @@ -58,7 +58,7 @@ public struct ContentView: View {
}
}
}

private func customFontsContent() -> some View {
Section(header: Text("Custom")) {
ForEach(CocoaFont.customFonts, id: \.name) { font in
Expand All @@ -68,15 +68,15 @@ public struct ContentView: View {
}
}
}

private func colorContent() -> some View {
Color
.resource(.colorExample)
.overlay(DimmView())
.edgesIgnoringSafeArea(.all)
.overlay(CurrentColorSchemeLabel())
}

private func imageContent() -> some View {
Image
.resource(.imageExample)
Expand All @@ -91,14 +91,14 @@ public struct ContentView: View {
private struct DimmView: View {
@Environment(\.colorScheme)
private var colorScheme

var body: some View {
VStack {
LinearGradient(
gradient: Gradient(
colors: [
(colorScheme == .dark ? .black : .white),
.clear
.clear,
]
),
startPoint: .top,
Expand All @@ -112,26 +112,28 @@ private struct DimmView: View {
private struct CurrentColorSchemeLabel: View {
@Environment(\.colorScheme)
private var colorScheme

var body: some View {
HStack {
Text("ColorScheme:")
.font(Font(
colorScheme == .dark
? CocoaFont.primary(ofSize: 18, weight: .bold)
: CocoaFont.secondary(ofSize: 18, weight: .bold)
))
.font(
Font(
colorScheme == .dark
? CocoaFont.primary(ofSize: 18, weight: .bold)
: CocoaFont.secondary(ofSize: 18, weight: .bold)
)
)
Text("\(name(for: colorScheme))")
.font(.system(size: 18, weight: .regular))
}
.padding()
.background(
(colorScheme == .dark ? Color.black : .white)
.opacity(0.4)
)
.cornerRadius(8)
.padding()
.background(
(colorScheme == .dark ? Color.black : .white)
.opacity(0.4)
)
.cornerRadius(8)
}

private func name(for colorSheme: ColorScheme) -> String {
switch colorScheme {
case .light: return "Light"
Expand Down
6 changes: 3 additions & 3 deletions Example/Sources/SPMGenExampleCore/Extesnions/Optional+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ extension Optional {
public var isNil: Bool {
self == nil
}

public var isNotNil: Bool {
self != nil
}

public func or(_ defaultValue: @autoclosure () -> Wrapped?) -> Wrapped? {
self ?? defaultValue()
}

public func or(_ defaultValue: @autoclosure () -> Wrapped) -> Wrapped {
self ?? defaultValue()
}
Expand Down
Loading

0 comments on commit 581fab9

Please sign in to comment.