class ViewController: UIViewController { var hogehoge: UIView = UIView() func piyopiyo() { NotificationCenter.default.post(.hoge, object: hogehoge.snapshotImage()) self.dismiss(animated: true, completion: nil) } } extension UIView { func snapshotImage() -> UIImage? { UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0) guard let currentContext = UIGraphicsGetCurrentContext() else { UIGraphicsEndImageContext() return nil } layer.renderInContext(currentContext) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image } }