# \#inheritance

**URL:** https://forums.swift.org/tag/inheritance/71.md

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

---

## [Sendable subclassing](https://forums.swift.org/t/sendable-subclassing/90639)

<div class="topic-metadata">

**Author:** [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Replies:** 0\
**Last updated:** [November 10, 2026, 10:35pm UTC](https://forums.swift.org/t/sendable-subclassing/90639 "2026-11-10T22:35:00Z")

</div>

I just invented a trick that I wanted to share. So, normally you cannot subclass checked Sendable classes: class Base: Sendable { // error: Non-final class \`Base\` cannot conform to the \`Sendable\` protocol. let id: I…

---

## [\`override\` functions behaves differently in \`async\` and \`throws\`](https://forums.swift.org/t/override-functions-behaves-differently-in-async-and-throws/83998)

<div class="topic-metadata">

**Author:** [@akuzminskyi](https://forums.swift.org/u/akuzminskyi)\
**Replies:** 17\
**Last updated:** [April 8, 2026, 9:42pm UTC](https://forums.swift.org/t/override-functions-behaves-differently-in-async-and-throws/83998 "2026-04-08T21:42:14Z")

</div>

Hi, I have a such sample code class A { func funcAsync() async { print("a: async") } func funcThrows() throws { print("a: throws") } } class B: A { override func funcAsync() async { …

---

## [Created task unable to inherit actor isolation](https://forums.swift.org/t/created-task-unable-to-inherit-actor-isolation/84734)

<div class="topic-metadata">

**Author:** [@soumyamahunt](https://forums.swift.org/u/soumyamahunt)\
**Replies:** 1\
**Last updated:** [February 14, 2026, 11:39am UTC](https://forums.swift.org/t/created-task-unable-to-inherit-actor-isolation/84734 "2026-02-14T11:39:07Z")

</div>

I have an use-case for actor which matches following snippet: actor SomeActor { let executor = DispatchSerialQueue(label: "serial") var counter = 0 nonisolated var unownedExecutor: UnownedSerialExecutor { ex…

---

## [Why I cannot use the same static method signature in subclass?](https://forums.swift.org/t/why-i-cannot-use-the-same-static-method-signature-in-subclass/80459)

<div class="topic-metadata">

**Author:** [@Adrian](https://forums.swift.org/u/Adrian)\
**Replies:** 4\
**Last updated:** [June 15, 2025, 5:42am UTC](https://forums.swift.org/t/why-i-cannot-use-the-same-static-method-signature-in-subclass/80459 "2025-06-15T05:42:38Z")

</div>

I'm trying to understand how method dispatch works in Swift for static methods. I wrote the following example: class Parent { static func greet() { print("Hello from Parent") } } class Child: Parent { …

---

## [Class does not inherit initializer from superclass of superclass](https://forums.swift.org/t/class-does-not-inherit-initializer-from-superclass-of-superclass/72299)

<div class="topic-metadata">

**Author:** [@nmgswift](https://forums.swift.org/u/nmgswift)\
**Replies:** 6\
**Last updated:** [June 7, 2024, 11:03pm UTC](https://forums.swift.org/t/class-does-not-inherit-initializer-from-superclass-of-superclass/72299 "2024-06-07T23:03:19Z")

</div>

I'm probably just not using Swift correctly, but I am curious why this does not work. class A { var property: Int = 0 init(foo: Int) { print(foo) } } class B: A { init(bar: Int) { super.…

---

## [Missing warning or error when messing up initializer inheritance?](https://forums.swift.org/t/missing-warning-or-error-when-messing-up-initializer-inheritance/71353)

<div class="topic-metadata">

**Author:** [@Gero](https://forums.swift.org/u/Gero)\
**Replies:** 3\
**Last updated:** [April 24, 2024, 10:15am UTC](https://forums.swift.org/t/missing-warning-or-error-when-messing-up-initializer-inheritance/71353 "2024-04-24T10:15:39Z")

</div>

So I managed to instantiate an object of a subclass that had a property (in this case storing a closure) not initialized. At least I believe so, thus I would appreciate somebody taking a look at this and comment. I had t…

---

## [Is it bug in @Observation makro? Or feature?](https://forums.swift.org/t/is-it-bug-in-observation-makro-or-feature/68189)

<div class="topic-metadata">

**Author:** [@typoland](https://forums.swift.org/u/typoland)\
**Replies:** 0\
**Last updated:** [November 1, 2023, 12:50pm UTC](https://forums.swift.org/t/is-it-bug-in-observation-makro-or-feature/68189 "2023-11-01T12:50:06Z")

</div>

Hi everybody! I try to refactor my old code to new @Observable pattern. And I found strange behaviour when class is subclassed. First, I have defined protocol: protocol HasSourcesAndTargets { var sources: \[String\]…

---

## [Differences between type-inheritance clause & protocol composition syntax?](https://forums.swift.org/t/differences-between-type-inheritance-clause-protocol-composition-syntax/47940)

<div class="topic-metadata">

**Author:** [@1oo7](https://forums.swift.org/u/1oo7)\
**Replies:** 3\
**Last updated:** [November 1, 2023, 1:59am UTC](https://forums.swift.org/t/differences-between-type-inheritance-clause-protocol-composition-syntax/47940 "2023-11-01T01:59:01Z")

</div>

Four years ago, Swift 4 introduced protocol compositions to Swift via SE-0156, with a review in early 2017, which finally added a long-awaited Obj. C feature via the new single-ampersand syntax for type declarations: pr…

---

## [Why can you constrain to final classes and actors?](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256)

<div class="topic-metadata">

**Author:** [@anon9791410](https://forums.swift.org/u/anon9791410)\
**Replies:** 5\
**Last updated:** [May 30, 2023, 4:22pm UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256 "2023-05-30T16:22:49Z")

</div>

Is it intended to allow for later making the class non-final, or actors inheritable? final class Class { } actor Actor { } func ƒ(\_: some Class, \_: some Actor) { }

---

## [How to remove the inherited @MainActor attribute on stored properties](https://forums.swift.org/t/how-to-remove-the-inherited-mainactor-attribute-on-stored-properties/63821)

<div class="topic-metadata">

**Author:** [@rayaantaneja](https://forums.swift.org/u/rayaantaneja)\
**Replies:** 3\
**Last updated:** [March 21, 2023, 3:59am UTC](https://forums.swift.org/t/how-to-remove-the-inherited-mainactor-attribute-on-stored-properties/63821 "2023-03-21T03:59:48Z")

</div>

Hey, I just started learning about Swift Concurrency and was wondering if it would be possible to write code like this: class GameScene: SKScene { var imagesToUpload = \["cat1", "mouse1", "dog1"\] var lastUploaded…

---

## [Associated type inference doesn't work in a situation that I assumed it would](https://forums.swift.org/t/associated-type-inference-doesnt-work-in-a-situation-that-i-assumed-it-would/61056)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 1\
**Last updated:** [October 27, 2022, 1:51pm UTC](https://forums.swift.org/t/associated-type-inference-doesnt-work-in-a-situation-that-i-assumed-it-would/61056 "2022-10-27T13:51:15Z")

</div>

Anyone have any knowledge about the code below and the possibility of it working in some future? protocol A { associatedtype T } protocol B: A { var t: T { get } } struct X: B { // typealias T = Int // This l…

---

## [Returning a concrete type conforming to a protocol from a method when an existential of this protocol is expected](https://forums.swift.org/t/returning-a-concrete-type-conforming-to-a-protocol-from-a-method-when-an-existential-of-this-protocol-is-expected/59139)

<div class="topic-metadata">

**Author:** [@laclouis5](https://forums.swift.org/u/laclouis5)\
**Replies:** 4\
**Last updated:** [July 22, 2022, 2:17pm UTC](https://forums.swift.org/t/returning-a-concrete-type-conforming-to-a-protocol-from-a-method-when-an-existential-of-this-protocol-is-expected/59139 "2022-07-22T14:17:14Z")

</div>

Consider I have this abstract base class with one virtual method with a return type of Foo: class Foo { func foo() -\> Foo { fatalError("abstract") } } Because Foo is in covariant position, a subclass can return an …

---

## [Subclassing with Nested Generics](https://forums.swift.org/t/subclassing-with-nested-generics/56215)

<div class="topic-metadata">

**Author:** [@ok386](https://forums.swift.org/u/ok386)\
**Replies:** 3\
**Last updated:** [March 26, 2022, 11:11am UTC](https://forums.swift.org/t/subclassing-with-nested-generics/56215 "2022-03-26T11:11:33Z")

</div>

Hello. I've got the following classes I intend to use a base: protocol ListCellViewModel {} class BaseListCell\<ViewModel: ListCellViewModel\>: UITableViewCell { func configure(with model: ViewModel) { …

---

## [Using subtypes in the implementation of protocol properties and function return values](https://forums.swift.org/t/using-subtypes-in-the-implementation-of-protocol-properties-and-function-return-values/51430)

<div class="topic-metadata">

**Author:** [@lhunath](https://forums.swift.org/u/lhunath)\
**Replies:** 17\
**Last updated:** [February 21, 2022, 10:31pm UTC](https://forums.swift.org/t/using-subtypes-in-the-implementation-of-protocol-properties-and-function-return-values/51430 "2022-02-21T22:31:11Z")

</div>

Given the following interface: protocol Animal { var head : AnimalHead { get } } protocol AnimalHead {} A Horse module might implement it as such: struct Horse : Animal { // let head = HorseHead() // \[1\] l…

---

## [Problems inheriting a Universal Framework interface](https://forums.swift.org/t/problems-inheriting-a-universal-framework-interface/52971)

<div class="topic-metadata">

**Author:** [@SSopin](https://forums.swift.org/u/SSopin)\
**Replies:** 11\
**Last updated:** [November 11, 2021, 7:29pm UTC](https://forums.swift.org/t/problems-inheriting-a-universal-framework-interface/52971 "2021-11-11T19:29:03Z")

</div>

Hi everyone. I am a beginner at Swift. I am trying to extend Google's MLKit StrokePoint to make it Codable: import Foundation import MLKit class CodableStrokePoint: StrokePoint, Codable { public func encode(t…

---

## [What’s so special about UIView.init()?](https://forums.swift.org/t/what-s-so-special-about-uiview-init/48251)

<div class="topic-metadata">

**Author:** [@CrystDragon](https://forums.swift.org/u/CrystDragon)\
**Replies:** 5\
**Last updated:** [May 13, 2021, 10:44am UTC](https://forums.swift.org/t/what-s-so-special-about-uiview-init/48251 "2021-05-13T10:44:53Z")

</div>

I came across a very strange behavior in Swift lately. Normally, when using a meta type, I can only reference its required initializer. class A { init(\_ Val: Int) } let t = A.self t.init(3) // error This is expected…

---

## [Is there an ABI-compatible way to retrieve class inheritance hierarch?](https://forums.swift.org/t/is-there-an-abi-compatible-way-to-retrieve-class-inheritance-hierarch/44910)

<div class="topic-metadata">

**Author:** [@Kokluch](https://forums.swift.org/u/Kokluch)\
**Replies:** 0\
**Last updated:** [February 19, 2021, 4:16pm UTC](https://forums.swift.org/t/is-there-an-abi-compatible-way-to-retrieve-class-inheritance-hierarch/44910 "2021-02-19T16:16:22Z")

</div>

Hi, Is there an ABI-compatible way to retrieve class inheritance hierarch? I'm using GitHub - wickwirew/Runtime: A Swift Runtime library for viewing type info, and the dynamic getting and setting of properties. to achi…

---

## [Sub-class conformance ignored when reference to instance is casted to super class type](https://forums.swift.org/t/sub-class-conformance-ignored-when-reference-to-instance-is-casted-to-super-class-type/43681)

<div class="topic-metadata">

**Author:** [@camsoft](https://forums.swift.org/u/camsoft)\
**Replies:** 4\
**Last updated:** [January 8, 2021, 8:17pm UTC](https://forums.swift.org/t/sub-class-conformance-ignored-when-reference-to-instance-is-casted-to-super-class-type/43681 "2021-01-08T20:17:41Z")

</div>

Given this example: protocol ConformSomething { func whoAmI() } extension ConformSomething { func whoAmI() { print("Default implementation") } } class BaseClass: ConformSomething { } final class S…

---

## [Why can't protocol which inherits from PAT but constrains its associated types be used as existential?](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 11\
**Last updated:** [November 16, 2020, 10:18am UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051 "2020-11-16T10:18:13Z")

</div>

I was hoping this code would compile, but it does not: protocol A { associatedtype T } protocol B: A where T == Int { } var demo: B? = nil I get the usual error: Protocol 'B' can only be used as a generic co…

---

## [Is this the right way subclasses should handle a base class conforming to a protocol initializer?](https://forums.swift.org/t/is-this-the-right-way-subclasses-should-handle-a-base-class-conforming-to-a-protocol-initializer/39979)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 8\
**Last updated:** [September 4, 2020, 4:08am UTC](https://forums.swift.org/t/is-this-the-right-way-subclasses-should-handle-a-base-class-conforming-to-a-protocol-initializer/39979 "2020-09-04T04:08:38Z")

</div>

Let's start with: /// A type where an instance may be an independent copy of another instance, /// with various levels of copying for sub-objects. protocol Cloner { /// Creates a copy of the given instance, where su…

---

## [Do I have to re-define equality/hashing for NSObject sub-classes?](https://forums.swift.org/t/do-i-have-to-re-define-equality-hashing-for-nsobject-sub-classes/35529)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 0\
**Last updated:** [April 20, 2020, 7:45pm UTC](https://forums.swift.org/t/do-i-have-to-re-define-equality-hashing-for-nsobject-sub-classes/35529 "2020-04-20T19:45:48Z")

</div>

I forgot; are sub-classes automatically marked as conforming to their base classes protocols? Even if they would do the wrong thing? I'm guessing "yes" to both questions. For any of the protocols that can have automat…

---

## [Overriding properties](https://forums.swift.org/t/overriding-properties/35334)

<div class="topic-metadata">

**Author:** [@Camille\_Evinas](https://forums.swift.org/u/Camille_Evinas)\
**Replies:** 1\
**Last updated:** [April 14, 2020, 4:33pm UTC](https://forums.swift.org/t/overriding-properties/35334 "2020-04-14T16:33:21Z")

</div>

Hi, Swift rules state that any inherited property can be overridden whether it is implemented as a stored or computed property at source (parent class). I have been trying to illustrate this rule with an example, but X…

---

## [Deduplicating documentation comments through protocols or inheritance](https://forums.swift.org/t/deduplicating-documentation-comments-through-protocols-or-inheritance/35117)

<div class="topic-metadata">

**Author:** [@Saklad5](https://forums.swift.org/u/Saklad5)\
**Replies:** 0\
**Last updated:** [April 5, 2020, 2:53pm UTC](https://forums.swift.org/t/deduplicating-documentation-comments-through-protocols-or-inheritance/35117 "2020-04-05T14:53:04Z")

</div>

I consider two of Swift’s biggest strengths to be composition and documentation. That means using internal protocols to formalize implementation requirements and using Markdown to explain exactly what each declaration is…

---

## [Why can't a subclass use didSet to observe parent's private(set) properties?](https://forums.swift.org/t/why-cant-a-subclass-use-didset-to-observe-parents-private-set-properties/32298)

<div class="topic-metadata">

**Author:** [@SubjugaterCephalopod](https://forums.swift.org/u/SubjugaterCephalopod)\
**Replies:** 7\
**Last updated:** [January 7, 2020, 10:22pm UTC](https://forums.swift.org/t/why-cant-a-subclass-use-didset-to-observe-parents-private-set-properties/32298 "2020-01-07T22:22:05Z")

</div>

This seems to be a very valid use case where you need to act upon the parent's property changes at the earliest possible moment: import GameplayKit class GameCoordinator: GKStateMachine { // ❗️ Cannot observe read-…

---

## [Why can't we call superclass convenience initializer from subclass?](https://forums.swift.org/t/why-cant-we-call-superclass-convenience-initializer-from-subclass/13515)

<div class="topic-metadata">

**Author:** [@Lope](https://forums.swift.org/u/Lope)\
**Replies:** 17\
**Last updated:** [December 24, 2019, 8:38pm UTC](https://forums.swift.org/t/why-cant-we-call-superclass-convenience-initializer-from-subclass/13515 "2019-12-24T20:38:54Z")

</div>

I am subclassing UIKit class and I would like to be able to call it's convenience initializer (because it does things I can't do myself) and then do additional step related to my subclass only. I can't do that because I …

---

## [What kind of black magic reconciles protocol with class inheritance](https://forums.swift.org/t/what-kind-of-black-magic-reconciles-protocol-with-class-inheritance/30929)

<div class="topic-metadata">

**Author:** [@Alvae](https://forums.swift.org/u/Alvae)\
**Replies:** 3\
**Last updated:** [November 19, 2019, 9:53pm UTC](https://forums.swift.org/t/what-kind-of-black-magic-reconciles-protocol-with-class-inheritance/30929 "2019-11-19T21:53:26Z")

</div>

Hello everyone, Some of you may recognize a similar protocol from another of my posts: protocol Stack { associatedtype Element func push(element: Element) -\> S func pop() -\> (Self, Element?) } Say I want to ado…

---

## [Default Protocol Implementation Inheritance Behaviour - The current situation and what/if anything should be done about it](https://forums.swift.org/t/default-protocol-implementation-inheritance-behaviour-the-current-situation-and-what-if-anything-should-be-done-about-it/28049)

<div class="topic-metadata">

**Author:** [@dlbuckley](https://forums.swift.org/u/dlbuckley)\
**Replies:** 22\
**Last updated:** [August 30, 2019, 7:46am UTC](https://forums.swift.org/t/default-protocol-implementation-inheritance-behaviour-the-current-situation-and-what-if-anything-should-be-done-about-it/28049 "2019-08-30T07:46:12Z")

</div>

For a bit of background this stems from a bug I (and a number of other people) have reported on bugs.swift.org, the original being here: https://bugs.swift.org/browse/SR-103. The Current Situation For context let's star…

---

## [Swift - Generic Class Inheritence](https://forums.swift.org/t/swift-generic-class-inheritence/19893)

<div class="topic-metadata">

**Author:** [@thisisjak](https://forums.swift.org/u/thisisjak)\
**Replies:** 9\
**Last updated:** [January 28, 2019, 9:03pm UTC](https://forums.swift.org/t/swift-generic-class-inheritence/19893 "2019-01-28T21:03:32Z")

</div>

class Inheriting\<Key: Equatable\> { var key: Key? } class InheritenceTesting\<Key: Comparable, Value\>: Inheriting { var key: Key var values: \[Value\]? init (key: Key) { self.key = key } } Output Error: err…

---

## [Add \`intermediate\` keyword to subclass definition to mark that the actual direct superclass is unknown when the subclass is defined](https://forums.swift.org/t/add-intermediate-keyword-to-subclass-definition-to-mark-that-the-actual-direct-superclass-is-unknown-when-the-subclass-is-defined/14433)

<div class="topic-metadata">

**Author:** [@yusuke024](https://forums.swift.org/u/yusuke024)\
**Replies:** 10\
**Last updated:** [July 15, 2018, 6:23am UTC](https://forums.swift.org/t/add-intermediate-keyword-to-subclass-definition-to-mark-that-the-actual-direct-superclass-is-unknown-when-the-subclass-is-defined/14433 "2018-07-15T06:23:54Z")

</div>

Hello all. This is my first post on Swift Forums. I don't know if a proposal that addresses the similar problem already exists or not, so please forgive me if that's the case. Introduction Add intermediate keyword to …

---

## [Creating an object by passing a metatype to a generic function uses the default parameter values of the base class' init](https://forums.swift.org/t/creating-an-object-by-passing-a-metatype-to-a-generic-function-uses-the-default-parameter-values-of-the-base-class-init/12508)

<div class="topic-metadata">

**Author:** [@SubjugaterCephalopod](https://forums.swift.org/u/SubjugaterCephalopod)\
**Replies:** 14\
**Last updated:** [May 14, 2018, 8:36pm UTC](https://forums.swift.org/t/creating-an-object-by-passing-a-metatype-to-a-generic-function-uses-the-default-parameter-values-of-the-base-class-init/12508 "2018-05-14T20:36:29Z")

</div>

class Thing { var name: String required init(name: String = "Thing") { self.name = name } } class ThingSubclass: Thing { required init(name: String = "ThingSubclass") { super.init(na…

[Next page](https://forums.swift.org/tag/inheritance/71.md?match_all_tags=true&page=1&tags%5B%5D=inheritance)
