Instances in programming with swift

im currently doing the programming in swift course and they often time use the word instance, for example they would say “instance of the class” and i’ve been trying to google what it means, but havent found a definitive answer.

Hi @miraz16,
Google has plenty of links with the answer to your question. Anyways, to answer your question,

a Class is a definition, something like a blue print, specifications. However when an object is created from this class definition, it is called an instance.

Cheers,

Jayant

import UIKit

class Dog {
    func bark() {
        print("Woof, woof!")
    }
}

let d = Dog()
d.bark()

--output:--
Woof, woof!

d is an instance of the class Dog. It is also said that d is an object of class Dog.

Instances are of a type: the options I can think of are class, struct, enum, tuple, and closure. An object is specifically a class instance. (It’s a decades-old term from when classes were new.)

This topic was automatically closed after 166 days. New replies are no longer allowed.