This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIImageJPEGRepresentation(image, compressionRatio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func UIImageToDataJPEG2(image: UIImage, compressionRatio: CGFloat) -> Data? { | |
return autoreleasepool(invoking: { () -> Data? in | |
return UIImageJPEGRepresentation(image, compressionRatio) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class discardableThumbnail: NSDiscardableContent { | |
var thumbnail: UIImage! | |
var accessCounter: Int = 0 | |
init(image: UIImage) { | |
thumbnail = image | |
} | |
func beginContentAccess() -> Bool { | |
if !(self.thumbnail != nil) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func containsGestureRecognizer(recognizers: [UIGestureRecognizer]?, find: UIGestureRecognizer) -> Bool { | |
if let recognizers = recognizers { | |
for gr in recognizers { | |
if gr == find { | |
return true | |
} | |
} | |
} | |
return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |