Created
November 26, 2019 08:12
-
-
Save ha1f/44c8a5de0d64ce9b899a3e47ab856436 to your computer and use it in GitHub Desktop.
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
/// delegateなどを配列などに持ちたいときに使う | |
private final class WeakObject<T: AnyObject> { | |
weak var object: T? | |
init(_ object: T?) { | |
self.object = object | |
} | |
} | |
final class PageViewControllerDelegateMulticaster: NSObject, UIPageViewControllerDelegate { | |
private var targets: [WeakObject<UIPageViewControllerDelegate>] = [] | |
func add(_ delegate: UIPageViewControllerDelegate) { | |
targets.append(WeakObject(delegate)) | |
} | |
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { | |
targets.forEach { target in | |
guard let targetUnwrapped = target.object else { | |
return | |
} | |
targetUnwrapped.pageViewController?(pageViewController, didFinishAnimating: finished, previousViewControllers: previousViewControllers, transitionCompleted: completed) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment