Last active
December 1, 2018 11:39
-
-
Save steipete/306f56a0a03bf1e490e28c5109b54b05 to your computer and use it in GitHub Desktop.
Workaround for http://openradar.appspot.com/46395110
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 UndoManager { | |
@objc func workaround_pspdf_endUndoGrouping() { | |
guard self.groupingLevel > 0 else { return } | |
self.workaround_pspdf_endUndoGrouping() | |
} | |
// Ensure this is only called once! | |
fileprivate static func InstallWorkaroundForRdar46395110() { | |
let originalSelector = #selector(UndoManager.endUndoGrouping) | |
let swizzledSelector = #selector(UndoManager.workaround_pspdf_endUndoGrouping) | |
let undoManagerClass = UndoManager.self | |
let originalMethod = class_getInstanceMethod(undoManagerClass, originalSelector)! | |
let swizzledMethod = class_getInstanceMethod(undoManagerClass, swizzledSelector)! | |
let didAddMethod = class_addMethod(undoManagerClass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)) | |
if didAddMethod { | |
class_replaceMethod(undoManagerClass, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)) | |
} else { | |
method_exchangeImplementations(originalMethod, swizzledMethod); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment