I'm sorry to say the above answer was wrong.
An object's initializer cannot do anything asynchronous. Its job is to produce the object immediately, with all its properties initialized
--> This is absolutely wrong.
I've done successfully tons of multi-threaded programming for 10 years in Objective-C/C/Swift: without any memory leakage nor data accesses nor access races.
I've successfully made some objects initialized asynchronously in making my games, esp. when I need to make as many objects as being initialized in a performant way along with lots of lazy objects.
initializers can do asynchronous but the problem here is 'self' in the escaping closure of the following can not be modified.
init(reference: DocumentReference) {
FirestoreService().fetchDocument(documentReference: reference) {
(request: RequestModel) in
self.request = request
}
The closure in the initializer in detail is
{
@escaping [unowned self] (request: RequestModel) in
self.request = request
}
Therefore, 'self' in the closure will outlive the function.
And the code above seems that it is part of View type, created as structure.
From https://docs.swift.org/swift-book/LanguageGuide/Closures.html,
"If self is an instance of a structure or an enumeration, you can always refer to self implicitly. However, an escaping closure can’t capture a mutable reference to self when self is an instance of a structure or an enumeration. Structures and enumerations don’t allow shared mutability, as discussed in Structures and Enumerations Are Value Types."
Therefore, the 'self' can not be mutable.
It is why your code is getting the error messgage:" Escaping closure captures mutating 'self' parameter".
A better solution to this is moving the part to another place inside of the modifier like 'didAppear()'.
Because the questioner didn't provide more of his or her codes here.
I can't provide a more specific answer here.