# Is the 'existential' a value or ref type?

**URL:** <https://forums.swift.org/t/is-the-existential-a-value-or-ref-type/27817>\
**Category:** Using Swift\
**Created:** [August 12, 2019, 2:37pm UTC](https://forums.swift.org/t/is-the-existential-a-value-or-ref-type/27817 "2019-08-12T14:37:11Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [August 15, 2019, 3:57am UTC](https://forums.swift.org/t/is-the-existential-a-value-or-ref-type/27817/13 "2019-08-15T03:57:35Z")

</div>

There is hidden achievement to unlock in this setup.

First, we know that the "existential" type itself is a value type which has no value semantics unless it wraps another type with value semantics.

```swift
struct Existential<Value> {
  // invisible to the user
  var _value: Value
  // forwards all members of Value
}

```

Now let's see our protocols:

```swift
protocol P0 {
  // this is a `mutating set`
  var x: Int { get set }
}

// protocol is class bound but it still has a `mutating set`
protocol P1: AnyObject, P0 {}

// protocol is class bound but now we re-defined the property
// which implies that the `set` becomes `nonmutating`, it's just
// implicit in this context
protocol P2: AnyObject, P0 {
  var x: Int { get set }
}

// Non-class bound protocol with explicit `nonmutating set`
protocol P3: P0 {
  var x: Int { get nonmutating set }
}

// class bound and implicit `nonmutating set` like P2
protocol P4: AnyObject {
  var x: Int { get set }
}

```

Now think about how the following values would behave:

```swift
Existential<P0>.x = 1 // expected-error
Existential<P1>.x = 1 // expected-error
Existential<P2>.x = 1 // okay
Existential<P3>.x = 1 // okay 
Existential<P4>.x = 1 // okay - this is your first example

// your second example
Existential<P0 & AnyObject>.x = 1 // expected-error

```

---

_[View the full topic](https://forums.swift.org/t/is-the-existential-a-value-or-ref-type/27817)._
