CHAAANY ARCHIVE

swift mutating

1개의 기록을 주제별로 둘러보세요.

Swift mutating: struct·enum에서 self를 바꾸는 규칙

Swift의 mutating은 struct와 enum의 instance method가 property 또는 self 자체를 변경할 수 있다고 선언하는 keyword다. ‘struct의 모든 property는 기본적으로 immutable’해서 붙이는 것이 아니다. instance가 var인지 let인지, property가 var인지, method가 mutating인지 세 조건을 나눠 봐야 한다.struct property를 바꾸는 methodPoint의 좌표를 현재 instance 안에서 변경하려면 method 앞에 mutating을 붙인다.struct Point { var x: Int var y: Int mutating func moveBy(x deltaX: Int, y deltaY: I..

728x90