Assigning value to inout parameters within closure in Swift 3

Viewed 1638

I have an error when I try to assign a value to the function parameter while inside a completion block, I get an error that reads 'escaping closures can only capture inout parameters explicitly by value' .

How could I fix this? Any tip is much appreciated!

func fetchCurrentUser(user: inout User? ) {
    self.fetchUser(withId: AuthProvider.sharedInstance.currentUserId(), completionHandler: {
        fetchedUser in
        guard let newUser = fetchedUser else { return }
        user = newUser // error Here
    })
}
2 Answers
Related