Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift language features] Bind mutating functions #3015

Open
jkurdek opened this issue Feb 21, 2025 · 0 comments
Open

[Swift language features] Bind mutating functions #3015

jkurdek opened this issue Feb 21, 2025 · 0 comments

Comments

@jkurdek
Copy link
Member

jkurdek commented Feb 21, 2025

In Swift, mutating functions are functions that modify the state of a value type (i.e., struct or enum). By default, structures (struct) and enumerations (enum) are value types, meaning they are copied when assigned or passed around.

Because value types are immutable by default, Swift requires explicit marking of functions that modify them with the mutating keyword.

struct Counter {
    var value: Int = 0

    mutating func increment() {
        value += 1
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant