Skip to content

Commit f94fcc8

Browse files
committed
objc: add support for NSKVONotifying_ subclasses. closes #104
1 parent 737d9c1 commit f94fcc8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

objc/call_amd64.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import "C"
1111
import (
1212
"math"
1313
"reflect"
14+
"strings"
1415
"unsafe"
1516
)
1617

@@ -142,7 +143,17 @@ func goMethodCallEntryPoint(p uintptr) uintptr {
142143
sel := stringFromSelector(unsafe.Pointer(fetcher.Int()))
143144

144145
clsName := object{ptr: getObjectClass(obj).Pointer()}.className()
146+
// Sometimes newer versions of macOS dynamically create a "NSKVONotifying_"
147+
// prefixed subclass, which we won't have registered in classMap. However,
148+
// since it's a subclass, we can probably get away with looking up the class
149+
// that was inherited from based on the name part after the prefix.
150+
if strings.HasPrefix(clsName, "NSKVONotifying_") {
151+
clsName = strings.Replace(clsName, "NSKVONotifying_", "", 1)
152+
}
145153
clsInfo := classMap[clsName]
154+
if clsInfo.typ == nil {
155+
panic("unable to find registered class: " + clsName)
156+
}
146157
method := clsInfo.MethodForSelector(sel)
147158

148159
// Check if we have an internal pointer set for this object.

objc/call_arm64.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,17 @@ func goMethodCallEntryPoint(p uintptr) uintptr {
141141
sel := stringFromSelector(unsafe.Pointer(fetcher.Int()))
142142

143143
clsName := object{ptr: getObjectClass(obj).Pointer()}.className()
144+
// Sometimes newer versions of macOS dynamically create a "NSKVONotifying_"
145+
// prefixed subclass, which we won't have registered in classMap. However,
146+
// since it's a subclass, we can probably get away with looking up the class
147+
// that was inherited from based on the name part after the prefix.
148+
if strings.HasPrefix(clsName, "NSKVONotifying_") {
149+
clsName = strings.Replace(clsName, "NSKVONotifying_", "", 1)
150+
}
144151
clsInfo := classMap[clsName]
152+
if clsInfo.typ == nil {
153+
panic("unable to find registered class: " + clsName)
154+
}
145155
method := clsInfo.MethodForSelector(sel)
146156

147157
// Check if we have an internal pointer set for this object.

0 commit comments

Comments
 (0)