Junior — Middle
Kas saaksite selgitada, mis on viidetüüpi andmed?
sobes.tech AI
Vastus AI-lt
Reference type is a type whose variables do not store the data itself, but a reference (pointer) to the memory area where these data are located. For example, in Swift, classes are reference types. This means that when assigning or passing a class object, only the reference to the same instance is copied, not the object itself.
Example:
class Person {
var name: String
init(name: String) {
self.name = name
}
}
let person1 = Person(name: "Иван")
let person2 = person1
person2.name = "Петр"
print(person1.name) // Will output "Петр", because person1 and person2 refer to the same object
This differs from value types (e.g., structures), where the object itself is copied.