What is a 'non-nominal type' in Swift?

后端 未结 2 1771
天命终不由人
天命终不由人 2020-12-13 06:15

I see this error when trying to extend unorthodox \'types\' like (Int, Int), or Any:

Non-nominal type \'Any\' cannot be exte

2条回答
  •  孤街浪徒
    2020-12-13 07:09

    This is somewhat of a guess (edit: it's wrong, look at Brent's answer), but here goes:

    Any is a protocol, not an actual type. The word "Nominal" implies naming (based on the root of the word).

    So you can't extend Any because it's a protocol, not an actual type, and you can't extend (Int, Int) because that's just a tuple literal, again not an actual type that you could specify by name.


    Update:

    You can, of course, extend protocols. Any is not a protocol, it's (shocker) a non-nominal type which is something else. Read Brent's answer; he did a good job.

提交回复
热议问题