Sobes.tech
Intern

What is an object?

sobes.tech AI

Answer from AI

Class instance. The state of an object is determined by the values of its properties (variables), and its behavior — by its methods (functions).

// Example class
class Dog {
    // Property
    var name: String
    
    // Initializer
    init(name: String) {
        self.name = name
    }
    
    // Method
    func bark() {
        print("\(name) barks!")
    }
}

// Creating an object (instance of class Dog)
let myDog = Dog(name: "Rex")

// Interacting with the object
myDog.bark() // Outputs "Rex barks!"