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

crash occurs if the base class is NSObject #25

Closed
thekan23 opened this issue Jul 23, 2018 · 4 comments
Closed

crash occurs if the base class is NSObject #25

thekan23 opened this issue Jul 23, 2018 · 4 comments

Comments

@thekan23
Copy link

thekan23 commented Jul 23, 2018

class User: NSObject {
    let id: Int = 0
    let username: String = ""
    let email: String = ""
}

let info = try typeInfo(of: User.self) // crash occurs 
let property = try info.property(named: "username")
print("name: \(property.name)")
print("type: \(property.type)")

how fix this problem? and is there any plan to support objective-c language?

@wickwirew
Copy link
Owner

wickwirew commented Jul 23, 2018

Reproduced, thanks! When it was searching through the super classes it wasnt stopping at NSObject.

#26 should fix it. Would you mind giving the fix-nsobject-base branch a try?

@thekan23
Copy link
Author

thekan23 commented Jul 23, 2018

Thank you, i confirmed that it works well.
but real my problem is not fixed yet.

my real problem is below

import Realm
import RealmSwift

class RealmUser: Object {
    @objc dynamic var id: Int = 0
    @objc dynamic var username: String = ""
    @objc dynamic var email: String = ""
}

let realmInfo = try typeInfo(of: RealmUser.self)
let realmProperty = try realmInfo.property(named: "username")
print("name: \(realmProperty.name)")
print("type: \(realmProperty.type)")

Object -> RLMObjectBase -> NSObject

can this problem be solved? i hope to be..
thank you!!

@wickwirew
Copy link
Owner

hmmmm im not to sure. Id have to set up a realm project. However I wouldn't use this project with Realm. Setting a property via reflection with this lib wont actually trigger realm to actually save it. Out of curiosity whats the use case?

@thekan23
Copy link
Author

After read your comment, It seems to useless..

but if runtime library applied to unsupported type, I think it would be better to print error message instead of crash.

and that use case just simple class inheritance.. sorry (T_T)
thank you for your kindness.

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

2 participants