# Grammar of postfix-self expression

**URL:** <https://forums.swift.org/t/grammar-of-postfix-self-expression/39316>\
**Category:** Using Swift\
**Created:** [August 11, 2020, 11:35pm UTC](https://forums.swift.org/t/grammar-of-postfix-self-expression/39316 "2020-08-11T23:35:05Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![QuinceyMorris](https://avatars.discourse-cdn.com/v4/letter/q/d26b3c/32.png) [@QuinceyMorris](https://forums.swift.org/u/QuinceyMorris)\
**Post date:** [August 12, 2020, 2:03am UTC](https://forums.swift.org/t/grammar-of-postfix-self-expression/39316/3 "2020-08-12T02:03:24Z")

</div>

I think it actually makes sense, though it's a bit obscure.

For historical (Objective-C\*\*) reasons, you can add `.self` to pretty much any expression, and the resulting value is that same expression's value. In the informal lexical grammar of the document, `postfix-expression` basically represents the concept of "pretty much any expression".

(`[Int]` is a `postfix-expression` because it's a `primary-expression` because it's a `literal-expression` because it's a literal type name. It _isn't_ an `array-literal`. A literal array of 1 type would be `[Int.self]`, not `[Int]`.)

In most cases, there's no reason to add `.self`, but a type name literal _alone_ isn't treated as a value. Adding `.self` forces it to be treated as a value, so that you can (for example) pass the type as a parameter to a function.

* * *

\*\*In Obj-C, KVC always requires an object _and_ a non-empty key-path to access a value. To reference the object itself, you don't have a key-path, so NSObject defined a `self` method, which works as key-path "self" in KVC. It looks like this works in Swift too:

```swift
let myself = self[keyPath: \.self]

```

---

_[View the full topic](https://forums.swift.org/t/grammar-of-postfix-self-expression/39316)._
