# What changed about initialising instance variables?

**URL:** <https://forums.swift.org/t/what-changed-about-initialising-instance-variables/73765>\
**Category:** Using Swift\
**Tags:** init\
**Created:** [August 7, 2024, 1:07pm UTC](https://forums.swift.org/t/what-changed-about-initialising-instance-variables/73765 "2024-08-07T13:07:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brustolin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/brustolin/32/35271_2.png) [@brustolin](https://forums.swift.org/u/brustolin)\
**Post date:** [August 7, 2024, 1:07pm UTC](https://forums.swift.org/t/what-changed-about-initialising-instance-variables/73765/1 "2024-08-07T13:07:50Z")

</div>

I have this code working with Xcode 15, but it breaks when compiling it with Xcode 16:

```swift
class SelectorController : UITableViewController {
    
    private let repository = Repository.shared
    
    init() {
        super.init(style: .grouped) //ERROR: Property 'self.repository' not initialized at super.init call
    }
}

```

What changed? I could not find any update on the docs related to this.

Edit:

If I remove @MainActor from `Repository` the error goes away.

---

<div class="post-metadata">

**Author:** ![eskimo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/eskimo/32/13558_2.png) [@eskimo](https://forums.swift.org/u/eskimo)\
**Post date:** [August 8, 2024, 8:47am UTC](https://forums.swift.org/t/what-changed-about-initialising-instance-variables/73765/2 "2024-08-08T08:47:27Z")

</div>

Which version of Xcode 16 beta is this? And are you in Swift 6 language mode?

I tried replicating your problem with Xcode 16.0b5 and I saw two different results:

- In Swift 5 mode the code compiled just fine.

- In Swift 6 mode I got a concurrency error which I think makes sense [1].

My code is below.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

[1] It’s centred on whether `init()` is main-actor-isolated or not. Indeed, it’s exactly [this issue](https://forums.swift.org/t/unexpected-error-with-implementing-init-in-a-subclass/73776).

* * *

```swift
import UIKit

@MainActor
class Repository {
    static let shared = Repository()
}

class SelectorController: UITableViewController {
    
    private let repository = Repository.shared
    
    init() {
        super.init(style: .grouped)
    }
    
    required init?(coder: NSCoder) {
        fatalError()
    }
}

```

---

<div class="post-metadata">

**Author:** ![brustolin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/brustolin/32/35271_2.png) [@brustolin](https://forums.swift.org/u/brustolin)\
**Post date:** [August 8, 2024, 12:06pm UTC](https://forums.swift.org/t/what-changed-about-initialising-instance-variables/73765/3 "2024-08-08T12:06:46Z")

</div>

Thanks for the reply.

Im using Xcode 16b5 and Swift 5 but with `SWIFT_STRICT_CONCURRENCY` as `complete` to prepare to Swift 6.

I thought that since `UITableViewController` is annotated with `@MainActor`, the constructor would also be on the `MainActor`.

If this is how Swift 6 will behave, I would appreciate any reading suggestions to catch up with the changes. As I mentioned before, this error doesn't occur with Xcode 15 using the same settings.

Thank you very much!!

---

<div class="post-metadata">

**Author:** ![vns](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vns/32/37396_2.png) [@vns](https://forums.swift.org/u/vns)\
**Post date:** [August 8, 2024, 12:16pm UTC](https://forums.swift.org/t/what-changed-about-initialising-instance-variables/73765/4 "2024-08-08T12:16:06Z")

</div>

I think this might be relative to other topic:

> [@Swift Concurrency In Real Apps](https://forums.swift.org/t/swift-concurrency-in-real-apps/73790/3):
>
> I hear your feedback, but this particular issue: is a regression in Xcode 16 Beta 5 that's fixed by [[6.0][Concurrency] Implement a narrow carve out in the isolation override checking for `NSObject.init()`. by hborla · Pull Request #75749 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/pull/75749).
