             }
             return
         }
-        var delegate = self.delegate
-        var responder = delegate as? UIResponder
-        while delegate != nil || responder != nil {
-            if let errorFn = delegate?.layoutNode(_:didDetectError:) {
-                if error.isTransient {
-                    _unhandledError = nil
-                }
-                errorFn(self, error)
-                return
-            }
-            responder = responder?.next
-            delegate = responder as? LayoutDelegate
+        if let delegate = self.delegate(for: #selector(LayoutDelegate.layoutNode(_:didDetectError:))) {
+            if error.isTransient {
+                _unhandledError = nil
+            }
+            delegate.layoutNode?(self, didDetectError: error)
         }
     }
 

    // MARK: symbols

    private func localizedString(forKey key: String) -> String? {
        var delegate = self.delegate
        var responder = delegate as? UIResponder
        while delegate != nil || responder != nil {
            if let string = delegate?.layoutNode?(self, localizedStringForKey: key) {
                return string
            }
            responder = responder?.next
            delegate = responder as? LayoutDelegate
        }
        return nil
    }

    private func value(forKeyPath keyPath: String, in dictionary: [String: Any]) -> Any? {

import UIKit

/// Optional delegate protocol to be implemented by a LayoutNode's owner
@objc public protocol LayoutDelegate {

    /// Notify that an error occured in the node tree
    @objc optional func layoutNode(_ layoutNode: LayoutNode, didDetectError error: Error)
