'Inout arguments are not allowed to alias each other in Swift

iam getting this two errors when i call a function of my Object

"Inout arguments are not allowed to alias each other"

"Overlapping accesses to 'tim', but modification requires exclusive access; consider copying to a local variable"

I have change the class User to an structur and had to set mutating func and inout parameter but know work anymore.

var tim: User = User(username: "Timmi", name: "tim")
        
        tim.friendAnfrage(friend: &tim, appUser: &appInfo.appUser)
        
        var steven: User = User()
        steven.username = "Stevi"
        steven.name = "Steven"
        steven.friendAnfrage(friend: &steven, appUser: &appInfo.appUser)
        
        appInfo.appUser.newFriend(newFriend: &steven,appUser: &appInfo.appUser)
        

struct User: Identifiable{

var id = UUID()
var username: String = ""
var name: String = ""
var password: String = ""
var email: String = ""
var beschreibung: String = ""
var profilBild: UIImage?

var friends = [User]()
var friendAnfrage = [User]()
var anfrageGesendet = [User]()

var feed = [Post]()

mutating func addFriend(friend: inout User,appUser: inout User) {
    friend.friendAnfrage.append(appUser)
    appUser.anfrageGesendet.append(friend)
    
}
mutating func newFriend(newFriend: inout User, appUser: inout User) {
    friends.append(newFriend)
    newFriend.friends.append(appUser)
    
    for i in 0..<friendAnfrage.count {
        if friendAnfrage[i].username == newFriend.username {
            friendAnfrage.remove(at: i)
        }
    }
}
mutating func friendAnfrage(friend: inout User,appUser: inout User) {
    appUser.friendAnfrage.append(friend)
}

mutating func makePost(image: UIImage?,appUser: User) {
    
    guard let image = image else { return }

    let post: Post = Post(ersteller: appUser, image: image, datum: "2022")
    
    feed.append(post)
    
    for i in 0..<friends.count {
        friends[i].feed.append(post)
    }
}

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source