Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes if classes inherit from NSObject. #16

Open
Lukas-Stuehrk opened this issue Aug 8, 2018 · 3 comments
Open

Crashes if classes inherit from NSObject. #16

Lukas-Stuehrk opened this issue Aug 8, 2018 · 3 comments

Comments

@Lukas-Stuehrk
Copy link

If you try to reflect an instance of a class that inherits from NSObject, it will crash while accessing a null pointer when trying to reflect NSObject.

The minimal example would be:

class Foobar: NSObject {
    var stringProperty: String = "foobar"
}

let instance = Foobar()
try! properties(instance)

I have an example traceback in the attached screenshot. I tried with Swift 3.3 and Swift 4.1.

screen shot 2018-08-08 at 14 48 22

I see that there's already a workaround in the superclass reflection where we exclude the SwiftObject superclass:

guard let superclass = superclass, String(describing: unsafeBitCast(superclass.pointer, to: Any.Type.self)) != "SwiftObject" else {

Would it make sense to exclude the NSObject superclass in the same way? Or is reflecting on classes inherited from NSObject in general not supported?

@GRGBISHOW
Copy link

The same issue here..! Do you have any solutions?

@robertjpayne
Copy link
Member

@Lukas-Stuehrk @GRGBISHOW you two may want to look at https://github.com/wickwirew/Runtime it's a bit more maintained than this library and functions very similarly.

@Lukas-Stuehrk
Copy link
Author

Thanks for the input, @robertjpayne. I had a look at Runtime before I reported the bug. It also crashes when objects inherit from NSObject.

I can provide a fix for this issue. It's just that it might be a surprising change, because it would simply stop to look for inherited properties from the NSObject superclass. That's why I wanted to discuss the issue first.

I can also report the issue at the Runtime project. But the fix looked much more complicated over there 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants