Skip to content

Commit

Permalink
Applied formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime committed Apr 24, 2024
1 parent 2950861 commit d0510a2
Show file tree
Hide file tree
Showing 202 changed files with 1,411 additions and 1,916 deletions.
14 changes: 7 additions & 7 deletions Dangerfile.swift
Expand Up @@ -10,9 +10,9 @@ let sourceChanges = allSourceFiles.contains { $0.hasPrefix("Source") }
let isNotTrivial = !danger.github.pullRequest.title.contains("#trivial")
if isNotTrivial && noChangelogEntry && sourceChanges {
danger.warn("""
Any changes to library code should be reflected in the Changelog.
Please consider adding a note there.
""")
Any changes to library code should be reflected in the Changelog.
Please consider adding a note there.
""")
}

// Make it more obvious that a PR is a work in progress and shouldn't be merged yet
Expand All @@ -30,18 +30,18 @@ if (danger.github.pullRequest.additions ?? 0) > 500 {
let addedSwiftLibraryFiles = danger.git.createdFiles.contains { $0.fileType == .swift && $0.hasPrefix("Source") }
let deletedSwiftLibraryFiles = danger.git.deletedFiles.contains { $0.fileType == .swift && $0.hasPrefix("Source") }
let modifiedCarthageXcodeProject = danger.git.modifiedFiles.contains { $0.contains("TPPDF.xcodeproj") }
if (addedSwiftLibraryFiles || deletedSwiftLibraryFiles) && !modifiedCarthageXcodeProject {
if addedSwiftLibraryFiles || deletedSwiftLibraryFiles, !modifiedCarthageXcodeProject {
fail("Added or removed library files require the Carthage Xcode project to be updated.")
}

// Warning message for not updated package manifest(s)
let manifests = [
"TPPDF.podspec",
"Package.swift",
"Package.resolved"
"Package.resolved",
]
let updatedManifests = manifests.filter { manifest in danger.git.modifiedFiles.contains { $0.name == manifest } }
if !updatedManifests.isEmpty && updatedManifests.count != manifests.count {
if !updatedManifests.isEmpty, updatedManifests.count != manifests.count {
let notUpdatedManifests = manifests.filter { !updatedManifests.contains($0) }
let updatedArticle = updatedManifests.count == 1 ? "The " : ""
let updatedVerb = updatedManifests.count == 1 ? "was" : "were"
Expand All @@ -54,7 +54,7 @@ if !updatedManifests.isEmpty && updatedManifests.count != manifests.count {

// Warn when library files has been updated but not tests.
let testsUpdated = danger.git.modifiedFiles.contains { $0.hasPrefix("Tests") }
if sourceChanges && !testsUpdated {
if sourceChanges, !testsUpdated {
warn("The library files were changed, but the tests remained unmodified. Consider updating or adding to the tests to match the library changes.")
}

Expand Down
8 changes: 4 additions & 4 deletions Example macOS/Example/AppDelegate.swift
Expand Up @@ -11,17 +11,17 @@ import SwiftUI

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

var window: NSWindow!

func applicationDidFinishLaunching(_ aNotification: Notification) {
func applicationDidFinishLaunching(_: Notification) {
let contentView = ContentView()

window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered,
defer: false)
defer: false
)
window.title = "TPPDF Examples"
window.center()
window.setFrameAutosaveName("Main Window")
Expand All @@ -30,7 +30,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
window.setFrameAutosaveName("main")
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
true
}
}
5 changes: 1 addition & 4 deletions Example macOS/Example/UI/ContentView.swift
Expand Up @@ -6,19 +6,16 @@
// Copyright © 2022 techprimate GmbH. All rights reserved.
//

import SwiftUI
import Combine
import SwiftUI
import TPPDF

class ContentViewModel: ObservableObject {

@Published var url: URL?
@State var selectedFactory = Examples.defaultFactory

}

struct ContentView: View {

@ObservedObject var viewModel = ContentViewModel()

var body: some View {
Expand Down
73 changes: 36 additions & 37 deletions Example macOS/Example/UI/PDFView+SwiftUI.swift
Expand Up @@ -10,52 +10,51 @@ import PDFKit
import SwiftUI

#if os(macOS)
import AppKit

struct PDFKitRepresentedView: NSViewRepresentable {

var url: URL?

func makeNSView(context: NSViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.NSViewType {
let pdfView = PDFView()
if let url = self.url {
pdfView.document = PDFDocument(url: url)
} else {
pdfView.document = nil
import AppKit

struct PDFKitRepresentedView: NSViewRepresentable {
var url: URL?

func makeNSView(context _: NSViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.NSViewType {
let pdfView = PDFView()
if let url = url {
pdfView.document = PDFDocument(url: url)
} else {
pdfView.document = nil
}
return pdfView
}
return pdfView
}

func updateNSView(_ nsView: NSView, context: NSViewRepresentableContext<PDFKitRepresentedView>) {
guard let pdfView = nsView as? PDFView else {
return
}
if let url = self.url {
pdfView.document = PDFDocument(url: url)
} else {
pdfView.document = nil
func updateNSView(_ nsView: NSView, context _: NSViewRepresentableContext<PDFKitRepresentedView>) {
guard let pdfView = nsView as? PDFView else {
return
}
if let url = url {
pdfView.document = PDFDocument(url: url)
} else {
pdfView.document = nil
}
}
}
}

#elseif os(iOS)
import UIKit
import UIKit

struct PDFKitRepresentedView: UIViewRepresentable {
let url: URL
struct PDFKitRepresentedView: UIViewRepresentable {
let url: URL

init(_ url: URL) {
self.url = url
}
init(_ url: URL) {
self.url = url
}

func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
// Create a `PDFView` and set its `PDFDocument`.
let pdfView = PDFView()
pdfView.document = PDFDocument(url: self.url)
return pdfView
}
func makeUIView(context _: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
// Create a `PDFView` and set its `PDFDocument`.
let pdfView = PDFView()
pdfView.document = PDFDocument(url: url)
return pdfView
}

func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {}
}
func updateUIView(_: UIView, context _: UIViewRepresentableContext<PDFKitRepresentedView>) {}
}

#endif
8 changes: 4 additions & 4 deletions Package.swift
Expand Up @@ -6,28 +6,28 @@ let package = Package(
name: "TPPDF",
platforms: [
.iOS(.v9),
.macOS(.v10_14)
.macOS(.v10_14),
],
products: [
.library(name: "TPPDF", targets: ["TPPDF"]),
],
dependencies: [
.package(url: "https://github.com/Quick/Quick", .exact("3.1.2")),
.package(url: "https://github.com/Quick/Nimble", .exact("9.2.1")),
.package(url: "https://github.com/Quick/Nimble", .exact("9.2.1")),
],
targets: [
.target(name: "TPPDF", path: "Source"),
.testTarget(name: "TPPDFTests", dependencies: [
"TPPDF",
"Quick",
"Nimble"
"Nimble",
], resources: [
.copy("resources/sample.pdf"),
]),
.testTarget(name: "TPPDFIntegrationTests", dependencies: [
"TPPDF",
"Quick",
"Nimble"
"Nimble",
], resources: [
.copy("resources/50-pages.pdf"),
]),
Expand Down
2 changes: 0 additions & 2 deletions Shared iOS/UI/AppDelegate.swift
Expand Up @@ -10,7 +10,5 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

}
9 changes: 4 additions & 5 deletions Shared iOS/UI/ExamplesListViewController.swift
Expand Up @@ -10,12 +10,11 @@ import Foundation
import UIKit

class ExamplesListViewController: UITableViewController {

override func numberOfSections(in tableView: UITableView) -> Int {
override func numberOfSections(in _: UITableView) -> Int {
return Examples.factories.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
return Examples.factories[section].examples.count
}

Expand All @@ -30,7 +29,7 @@ class ExamplesListViewController: UITableViewController {
return cell
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
return Examples.factories[section].header
}

Expand All @@ -40,7 +39,7 @@ class ExamplesListViewController: UITableViewController {
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "show-example", let dest = segue.destination as? ViewController, let index = sender as? IndexPath {
if segue.identifier == "show-example", let dest = segue.destination as? ViewController, let index = sender as? IndexPath {
let section = Examples.factories[index.section].examples
let item = section[index.row]

Expand Down
15 changes: 7 additions & 8 deletions Shared iOS/UI/ViewController.swift
Expand Up @@ -6,13 +6,12 @@
// Copyright © 2019 Philip Niedertscheider. All rights reserved.
//

import UIKit
import TPPDF
import UIKit

class ViewController: UIViewController {

@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var progressView: UIProgressView!
@IBOutlet var webView: UIWebView!
@IBOutlet var progressView: UIProgressView!

var progressObserver: NSObjectProtocol!

Expand All @@ -38,7 +37,7 @@ class ViewController: UIViewController {
print("Preparation took: " + TimeUtils.stringFromTimeInterval(interval: CFAbsoluteTimeGetCurrent() - startTime))
startTime = CFAbsoluteTimeGetCurrent()
/* ---- Execution Metrics ---- */

var generator: PDFGeneratorProtocol
if documents.count > 1 {
generator = PDFMultiDocumentGenerator(documents: documents)
Expand All @@ -47,15 +46,15 @@ class ViewController: UIViewController {
}
generator.debug = exampleFactory is ExperimentFactory

self.progressView.observedProgress = generator.progress
observer = generator.progress.observe(\.completedUnitCount) { (p, _) in
progressView.observedProgress = generator.progress
observer = generator.progress.observe(\.completedUnitCount) { p, _ in
print(p.localizedDescription ?? "")
}
DispatchQueue.global(qos: .background).async {
do {
let url = try generator.generateURL(filename: "Example.pdf")
print("Output URL:", url)

/* ---- Execution Metrics ---- */
print("Generation took: " + TimeUtils.stringFromTimeInterval(interval: CFAbsoluteTimeGetCurrent() - startTime))
/* ---- Execution Metrics ---- */
Expand Down
5 changes: 2 additions & 3 deletions Shared/Examples/DocumentSettingsExampleFactory.swift
Expand Up @@ -7,14 +7,13 @@
//

#if os(iOS)
import UIKit
import UIKit
#elseif os(macOS)
import AppKit
import AppKit
#endif
import TPPDF

class DocumentSettingsExampleFactory: ExampleFactory {

func generateDocument() -> [PDFDocument] {
let document = PDFDocument(format: .a4)
document.background.color = .green
Expand Down
10 changes: 2 additions & 8 deletions Shared/Examples/Examples.swift
Expand Up @@ -9,21 +9,16 @@
import Foundation

struct ExampleSection {

let header: String
let examples: [Example]

}

struct Example {

let name: String
let factory: ExampleFactory

}

enum Examples {

static var factories: [ExampleSection] {
[
.init(header: "Popular Examples", examples: [
Expand All @@ -42,16 +37,15 @@ enum Examples {
.init(name: "Pagination", factory: PaginationExampleFactory()),
.init(name: "Text Styles", factory: TextStylesExampleFactory()),
.init(name: "External Documents", factory: ExternalDocumentExampleFactory()),
.init(name: "Object Attributes", factory: ObjectAttributesExampleFactory())
.init(name: "Object Attributes", factory: ObjectAttributesExampleFactory()),
]),
.init(header: "Developer Examples", examples: [
.init(name: "Experiment", factory: ExperimentFactory()),
])
]),
]
}

static var defaultFactory: Example {
return factories[1].examples[0]
}
}

0 comments on commit d0510a2

Please sign in to comment.