InterviewSolution
| 1. |
Let us take into consideration the following code snippet in ios Swift: |
|
Answer» struct Course{ var toughness: INT = 3}var courseOne = Course()var courseTwo = courseOnecourseTwo.toughness = 4 What will be the respective values of courseOne.toughness and courseTwo.toughness? If Course was a class instead of a struct, would the values be any DIFFERENT? The value of courseOne.toughness will be 3 and the value of courseTwo.toughness will be 4 if Course is a structure since Structures in ios Swift are value types and the following line just copies the courseOne to courseTwo by value and not by reference: var courseTwo = courseOneIf Course was a class instead of a struct, then the above given line would copy courseOne to courseTwo by reference and therefore, the values of both courseOne and courseTwo would be 4 by the end of the code snippet as they have the same ADDRESS. CLASSES in ios Swift are Reference types therefore both the given courses have the same address. |
|