# Crash when dynamic dispatch method For Class Extension Method

**URL:** <https://forums.swift.org/t/crash-when-dynamic-dispatch-method-for-class-extension-method/19335>\
**Category:** Using Swift\
**Created:** [January 8, 2019, 2:49pm UTC](https://forums.swift.org/t/crash-when-dynamic-dispatch-method-for-class-extension-method/19335 "2019-01-08T14:49:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [January 8, 2019, 5:20pm UTC](https://forums.swift.org/t/crash-when-dynamic-dispatch-method-for-class-extension-method/19335/2 "2019-01-08T17:20:24Z")

</div>

This is a low-level implementation detail, but subclasses of NSObject use a different implementation of reference counting from pure Swift classes. That's why you get a crash in the Swift runtime: it's trying to retain a subclass of NSObject using the logic that makes sense for pure Swift objects.

(Strictly speaking, maybe this retain isn't necessary, but I still wouldn't bet on this working in general.)

As an aside, if you're going to use the Objective-C runtime to change method implementations, you should always mark those methods as `dynamic`. Otherwise, the compiler might try to inline calls to those methods, and you won't get the implementation you're expecting.

---

_[View the full topic](https://forums.swift.org/t/crash-when-dynamic-dispatch-method-for-class-extension-method/19335)._
