[swift-evolution] [Proposal] Remove behavior on AnyObject that allows any obj-c method to be called on it

Brent Royal-Gordon brent at architechies.com
Wed Mar 23 23:12:09 CDT 2016


> Just thinking out loud — ‘dynamic’ as an attribute on an object, allowing arbitrary method calls that are dispatched dynamically...
> 
> let foo: @dynamic AnyObject = Foo()
> foo.someWeirdMethod()
> 
> for thing in things {
>     (thing as @dynamic).bar()
> }
> 
> Dynamic as a type:
> 
> let foo: dynamic = Foo()
> foo.someWeirdMethod()
> 
> for thing in things {
>     (thing as dynamic).bar()
> }
> 
> Since the dynamic keyword defines a function that goes through runtime dispatch, the same very runtime dispatch that current AnyObject calls go through, it would make sense for the new stuff to be called something like dynamic or dynamic_binding or DynamicObject or whatever.

Or add a "here there be dragons" keyword on the expression, like the `try` keyword. Straw syntax:

	let foo = Foo()
	yolo foo.someWeirdMethod()

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list