# \#self

**URL:** https://forums.swift.org/tag/self/245.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Constrained generic \`T\` behaves like \`Self\` - so what is currently \`self\` in my generic initializer here?](https://forums.swift.org/t/constrained-generic-t-behaves-like-self-so-what-is-currently-self-in-my-generic-initializer-here/62832)

<div class="topic-metadata">

**Author:** [@hgraves](https://forums.swift.org/u/hgraves)\
**Replies:** 4\
**Last updated:** [January 29, 2023, 3:06am UTC](https://forums.swift.org/t/constrained-generic-t-behaves-like-self-so-what-is-currently-self-in-my-generic-initializer-here/62832 "2023-01-29T03:06:28Z")

</div>

open class RecordEncoder: NSCoder { required public init(coder: NSCoder) { } public init?\<T\>(from: Record\<T\>) where T: NSCoder { return nil } public init(record: RecordEncoder.Type, s…

---

## [Implicitly unowned self is bug prone](https://forums.swift.org/t/implicitly-unowned-self-is-bug-prone/58865)

<div class="topic-metadata">

**Author:** [@nh7a](https://forums.swift.org/u/nh7a)\
**Replies:** 9\
**Last updated:** [January 21, 2023, 5:15am UTC](https://forums.swift.org/t/implicitly-unowned-self-is-bug-prone/58865 "2023-01-21T05:15:46Z")

</div>

Hi there, Today, I realized that self wasn't implicitly captured when it's within an "unowned" block as below. func f1() { runBlock { \[unowned self\] in // self is safe here since runBlock won't run this block if …

---

## [Can't assign to self in initializer in protocol extension when protocol inherits from NSCoding](https://forums.swift.org/t/cant-assign-to-self-in-initializer-in-protocol-extension-when-protocol-inherits-from-nscoding/59588)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 1\
**Last updated:** [August 11, 2022, 3:28pm UTC](https://forums.swift.org/t/cant-assign-to-self-in-initializer-in-protocol-extension-when-protocol-inherits-from-nscoding/59588 "2022-08-11T15:28:27Z")

</div>

Why am I not able to assign to self in this context? Is there a way around it? protocol Test: NSCoding { } extension Test { init (equalTo other: Self) throws { self = other // Error: Cannot assign to v…

---

## [Unexpected difference in behaviour between a class extension and a protocol extension when inferring types for self / Self](https://forums.swift.org/t/unexpected-difference-in-behaviour-between-a-class-extension-and-a-protocol-extension-when-inferring-types-for-self-self/59553)

<div class="topic-metadata">

**Author:** [@shim](https://forums.swift.org/u/shim)\
**Replies:** 0\
**Last updated:** [August 10, 2022, 1:31am UTC](https://forums.swift.org/t/unexpected-difference-in-behaviour-between-a-class-extension-and-a-protocol-extension-when-inferring-types-for-self-self/59553 "2022-08-10T01:31:40Z")

</div>

I have the following function in an extension on a class (in my case XCUIElement but I think this setup could apply to a lot of contexts quite easily) which has a closure with a parameter of Self. It's useful to do this …

---

## [Cannot reference invalid declaration 'self' with \`lazy var\`](https://forums.swift.org/t/cannot-reference-invalid-declaration-self-with-lazy-var/57285)

<div class="topic-metadata">

**Author:** [@akuzminskyi](https://forums.swift.org/u/akuzminskyi)\
**Replies:** 2\
**Last updated:** [May 13, 2022, 3:07am UTC](https://forums.swift.org/t/cannot-reference-invalid-declaration-self-with-lazy-var/57285 "2022-05-13T03:07:10Z")

</div>

Hi, I have probably a strange compiling error for the following code import Foundation class BB { func process(val: @escaping () -\> Void) {} } class AA { let bb = BB() func cc() -\> Int? { return nil } …

---

## [How does work on Swift? about class func return Self](https://forums.swift.org/t/how-does-work-on-swift-about-class-func-return-self/53713)

<div class="topic-metadata">

**Author:** [@RbBtSn0w](https://forums.swift.org/u/RbBtSn0w)\
**Replies:** 0\
**Last updated:** [November 26, 2021, 3:12am UTC](https://forums.swift.org/t/how-does-work-on-swift-about-class-func-return-self/53713 "2021-11-26T03:12:16Z")

</div>

Through Xcode's own controlparts feature, the header file of NSCollectionLayoutGroup below UIKit is converted into Swift file, and an interesting problem was found. Class func is the type that requires a range of Self k…

---

## ["Attempting to store to property within its own willSet" warning not shown if explicit self is used?](https://forums.swift.org/t/attempting-to-store-to-property-within-its-own-willset-warning-not-shown-if-explicit-self-is-used/52527)

<div class="topic-metadata">

**Author:** [@ChrisOffner](https://forums.swift.org/u/ChrisOffner)\
**Replies:** 3\
**Last updated:** [October 1, 2021, 7:36pm UTC](https://forums.swift.org/t/attempting-to-store-to-property-within-its-own-willset-warning-not-shown-if-explicit-self-is-used/52527 "2021-10-01T19:36:39Z")

</div>

I recently came across this incorrect code in a project: struct Video { var progress: Float? { willSet { guard let value = newValue else { self.progress = nil retu…

---

## [Why is implicit \`\[weak self\]\` not the norm?](https://forums.swift.org/t/why-is-implicit-weak-self-not-the-norm/49232)

<div class="topic-metadata">

**Author:** [@GabrielBrodersen](https://forums.swift.org/u/GabrielBrodersen)\
**Replies:** 19\
**Last updated:** [June 9, 2021, 1:48am UTC](https://forums.swift.org/t/why-is-implicit-weak-self-not-the-norm/49232 "2021-06-09T01:48:36Z")

</div>

After browsing the web for this question and learning about memory retain cycles in Swift (and how to deal with them), it is easy to get the impression that adding the capture list \[weak self\] is often the solution and r…

---

## [\`self\` within initializer expression of stored type property is \`unresolved identifier\`](https://forums.swift.org/t/self-within-initializer-expression-of-stored-type-property-is-unresolved-identifier/23439)

<div class="topic-metadata">

**Author:** [@mohsen](https://forums.swift.org/u/mohsen)\
**Replies:** 2\
**Last updated:** [April 21, 2019, 8:13am UTC](https://forums.swift.org/t/self-within-initializer-expression-of-stored-type-property-is-unresolved-identifier/23439 "2019-04-21T08:13:44Z")

</div>

As far as I know Stored type properties are lazily initialized on their first access. (ref) So why can't we refer to self within initializer expression of a stored type property? class Foo { static let name = S…
