You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I tried to use the Runtime and faced an issue with an object that inherits from the UIView. Property offsets were wrong. When I dug deeper I found that offsets don't count the instance size of UIView itself. I was able to workaround by modifying ClassMetadata's toTypeInfo() method like this:
mutatingfunc toTypeInfo()->TypeInfo{varinfo=TypeInfo(metadata:self)
info.mangledName =mangledName()
info.properties =properties()
info.genericTypes =Array(genericArguments())var_sc:ClassMetadata?=selfwhilevar sc = _sc?.superClassMetadata()?.asClassMetadata(){
info.inheritance.append(sc.type)letsuperInfo= sc.toTypeInfo()
info.properties.append(contentsOf: superInfo.properties)
_sc = sc
}
// Fix offset because of the obj-c inheritance if needed.
// Fix own properties only.
iflet sc = _sc,let superClass = pointer.pointee.superClass as?AnyObject.Type{letsize=class_getInstanceSize(superClass)- class_getInstanceSize(NSObject.self)foriin0..<numberOfFields(){
info.properties[i].offset +=numericCast(size) // <--- I also made the offset writable to simplify things
}}return info
}
I doubt it's the proper way of doing it and I was just curious If the issue can be fixed. Anyway, is it possible to add support for Swift objects inherited from objective-c classes?
The text was updated successfully, but these errors were encountered:
Hi, I tried to use the
Runtime
and faced an issue with an object that inherits from theUIView
. Property offsets were wrong. When I dug deeper I found that offsets don't count the instance size ofUIView
itself. I was able to workaround by modifyingClassMetadata
'stoTypeInfo()
method like this:I doubt it's the proper way of doing it and I was just curious If the issue can be fixed. Anyway, is it possible to add support for Swift objects inherited from objective-c classes?
The text was updated successfully, but these errors were encountered: