0

I'm studying swift and I'm trying to understand the difference between classes and struct, which as I understand it, is in these two points: 1) Classes are reference types, Whereas structures are value types. That means That When you pass an instance of a structure to a function, return an instance from a function, or assign the value of a variable That Refers to a structure to another variable, the instance is copied. In other words, structures exhibit pass-by-value behavior. Swift strings, arrays, and dictionaries are all Implemented as structures. By contrast, class instances are passed by reference-no copy is taken. 2) Classes can be subclassed to add behavior; structures can not.

why these two errors? depends on the structure ?, because a class does not give me the same error. error message:

emacos
  • 541
  • 1
  • 8
  • 17
  • These errors have nothing to do with your question. – Colin Jul 07 '15 at 14:58
  • As explained in the referenced thread, methods that modify properties of a struct must be marked as "mutating". You'll find that in the Swift book as well. – Martin R Jul 07 '15 at 15:10

1 Answers1

0

The reason you're getting those errors is that by default, the properties of a value type (i.e. a struct) cannot be modified from within its instance methods (e.g. your newRad() and plusOne() methods).

trevorj
  • 2,029
  • 1
  • 16
  • 11