Contextual property wrappers

I was enjoying using property wrappers for its great customization abilities. But I recently encountered a case where it would be great for this feature to act specifically based on a context in which it is being used. Look at example:

@Smarttype var number = 1
func requiresPointer(_ pointer: UnsafePointer<Int>)
func requiresInt(_ int: Int)

requiresPointer(number) //Would be great to have this, imo
requiresInt(number) //Works like a miracle

//I belive it can be something like this under the hood
struct Smarttype {
    var wrappedValue: UnsafePointer<Int> { ... }
    var wrappedValue: Int { ... }

What do you think about this? @John_McCall

Well you could have the projected value to return a pointer for the Int. Besides that I think @Douglas_Gregor should have been the right person to ping not John. ;)

Personally I don‘t think that a contextual design would be the right decision. This flips everything about Swift and isn‘t really a pure property wrapper thing anymore.

I filed a bug about conditional property wrappers and got it confirmed, but someone would need to implement it.

Good thing to know. I suppose there is not much I can do about it, but to wait. :person_in_lotus_position:

I’ll take a look