SwiftUI:Cannot use mutating member on immutable value: ‘self‘ is immutable

Posted wuwuFQ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SwiftUI:Cannot use mutating member on immutable value: ‘self‘ is immutable相关的知识,希望对你有一定的参考价值。

error: Cannot use mutating member on immutable value: 'self' is immutable
我是在做数组append的时候报的错,这个时候说成员不可变,但我的成员是 var 修饰的。
那么解决方案:
如果是在函数中操作, mutating func 修饰一下函数。
对数组或其他成员变量,用 @State 修饰一下。
问题迎刃而解!

以上是关于SwiftUI:Cannot use mutating member on immutable value: ‘self‘ is immutable的主要内容,如果未能解决你的问题,请参考以下文章

SwiftUI:Cannot use mutating member on immutable value: ‘self‘ is immutable

SwiftUI Multiplatform 为 macOS 生成“Cannot find type 'MyClass' in scope”

ubuntu cheomium cannot use flash

he expression ‘userViewModel.getUserName()‘ cannot be inverted, so it cannot be used in a tw

Cannot use this in a static context

SyntaxError: Cannot use import statement outside a module