Tuesday, April 21, 2026
HomeiOS Developmentios - Declared string inside class retains reverting to authentic worth

ios – Declared string inside class retains reverting to authentic worth

[ad_1]

Model new to swift.

Im working into an issue the place a declared string inside a category retains reverting again to its authentic worth after I modify it.

class Calculation: ObservableObject {
var CalcString: String = "check"

func modifyCalcString(newData: String) {
    CalcString = CalcString + newData
    print(CalcString)
}

}

modifyCalcString is known as utilizing a button in an app view

Calculation().modifyCalcString(newData: digit)

(digit is a string)

my drawback is each time I name modifyCalcString it’s modified after which reverts again to its authentic worth.

for instance when calling modifyCalString with newData as “5” the print assertion contained in the perform will output “test5” however after printing it once more it reverts again to “check”

im fairly misplaced right here and would recognize the assistance.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments