What changed about initialising instance variables?

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

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.

1 Like

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.


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()
    }
}
2 Likes

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!!

I think this might be relative to other topic:

1 Like