Sobes.tech
Junior — Senior

Find bugs in the Swift example

livecode

Task condition

This example examines how the value of a property changes in a class and in a struct. The class SomeClass is declared with a variable value and a method changeValueInc(), which increments the value. The struct SomeStruct has a similar variable and method, but in Swift, a struct's method cannot modify properties without being marked as mutating. Below is the source code where attempting to modify value in the struct results in a compilation error.

class SomeClass {
    var value = 5
    
    func changeValueInc(){
        self.value += 1
    }
}

struct SomeStruct {
    var value = 5
    
    func changeValueInc(){
        self.value += 1
    }
}

let c = SomeClass()
c.changeValueInc()
let s = SomeStruct()
s.changeValueInc()

Your task is to determine why the code does not compile and suggest a fix.