Swift leave out .self to invoke a function which needs metatype? -


here code write:

func printtype<t: any>(one: t.type) {     print(one) } func printtype2<t: any>(one: t.type, name: string) {     print(one) } printtype(set<int>) printtype2(set<int>.self, name: "name") 

i wonder why printtype(set<int>) can work. , in printtype2(set<int>.self, name: "name"), can not leave out .self make work.

edit:

i want know rule imply when can omit .self. had tried find in apple official references, failed.

edit:

i test codes in xcode version 7.1 (7b91b).

i ask in apple official forum, , answer there:

this famous undocumented feature of swift, since 1.0 (or former > betas, cannot confirm).

when calling method or function single type argument, can omit > .self . guess feature included swift make sizeof-like functions > neat, not sure.

https://forums.developer.apple.com/thread/24980


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -