More examples

#21 · closed · 9 comments

View on GitHub ↗

NSExceptional

Some examples on how to use this library for Key-Value Coding would be great! If I can figure it out before you see this, I'll submit a PR for the readme. Sorry for the issue spam 🤪

Comments

NSExceptional

So, I figured it out, but it's… really, really verbose. It definitely needs a wrapper. I can make a PR for that, unless you're opposed to providing a high level API for this?

NSExceptional

> unless you're opposed to providing a high level API for this? I see on your Twitter you may already be working on this? 😎

Azoy

This is one of the things that I'm actually unsure about. I know that I want high level abstractions moved into their own packages and for this package to remain sort of like the bones for reflection, but my dilemma is deciding what exactly is "high level." So, to that end, I'm unsure where I stand on kvc type APIs and if they're too high level or just right for this library. (Aside, kvc for stored properties is fairly easy with what reflection we have now, but things like computed properties, function invocations, etc. are a tougher issue because that info isn't in the reflection data, hence the tweet 😛 )

NSExceptional

I feel you. If you want higher level APIs in a separate library, then I think this library does all it needs to on its own. It enables one to build this higher level APIs by exposing the metadata provided by the runtime as simply as possible

NSExceptional

> a tougher issue because that info isn't in the reflection data, hence the tweet 😛 Wait, which part isn't in the metadata? o_O How are you doing it if it's not part of the runtime?

Azoy

Essentially what I'm doing is using the runtime metadata and the user provided arguments to build a mangling to the computed property accessors or functions, so basically I wrote a Swift mangler using metadata. From there I just dlsym to get the function and then do a bunch of complicated thunking to correctly call the function.

NSExceptional

Oh what the heck. I didn't know the metadata didn't provide the address of the implementation. Does this apply to methods too or just computed properties? Related: do you know how to call getters for stored properties such that any `willSet`/`didSet`/other observers are invoked?

Azoy

Right, the metadata doesn't provide any addresses for anything (computed props, methods, subscripts, etc.)

NSExceptional

Wow. I was under the impression it did, since Joe is always boasting about how Swift is just as reflective as Objc… 😬 Guess not