View ConfirmationViewController-2.swift
extension ConfirmationViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return touch.view == gestureRecognizer.view
}
func handleTapOffModal(_ sender: UITapGestureRecognizer) {
dismiss(animated: true, completion: nil)
}
}
View ConfirmationViewController-1.swift
internal class ConfirmationViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTapOffModal(_:)))
tap.delegate = self
view.addGestureRecognizer(tap)
view.isUserInteractionEnabled = true
}
View ConfirmationViewController.swift
import UIKit
internal class ConfirmationViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTapOffModal(_:)))
tap.delegate = self
view.addGestureRecognizer(tap)
View isExcludedFromBackup.swift
struct FileHelpers {
@discardableResult static func addSkipBackupAttribute(url: URL) throws -> Bool {
var fileUrl = url
do {
if FileManager.default.fileExists(atPath: fileUrl.path) {
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = true
try fileUrl.setResourceValues(resourceValues)
}
return true
View discardableThumbnail.swift
final class discardableThumbnail: NSDiscardableContent {
var thumbnail: UIImage!
var accessCounter: Int = 0
init(image: UIImage) {
thumbnail = image
}
func beginContentAccess() -> Bool {
if !(self.thumbnail != nil) {
View example.swift
/// Example adding it the first time
let recognizer = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
view.addGestureRecognizer(recognizer)
/// Test if gesture already added, if added return else add the recognizer
guard containsGestureRecognizer(recognizers: view.gestureRecognizers, find: recognizer) == false else { return }
/// Add the recognizer
view.addGestureRecognizer(recognizer)
View recognizerhelper.swift
func containsGestureRecognizer(recognizers: [UIGestureRecognizer]?, find: UIGestureRecognizer) -> Bool {
if let recognizers = recognizers {
for gr in recognizers {
if gr == find {
return true
}
}
}
return false
}
View copyPDFtoData.swift
if let pdf = unlock(data: pdfData, password: "Hello World") {
print("You now have an unlocked CGPDFDocument")
print("Create a copy of the unlocked CGPDFDocument")
let pdfWithoutPassword = copyPDFtoData(pdf: pdf)
print("You how have a pdf without password information")
}
View load-example.swift
let pdfData = try Data(contentsOf: URL(fileURLWithPath: "Path to pdf"))
View unlock.swift
if let pdf = unlock(data: pdfData, password: "Hello World") {
print("You now have an unlocked CGPDFDocument")
}
func unlock(data: Data, password: String) -> CGPDFDocument? {
if let pdf = CGPDFDocument(CGDataProvider(data: data as CFData)!) {
guard pdf.isEncrypted == true else { return pdf }
guard pdf.unlockWithPassword("") == false else { return pdf }