Hey guys, I have one other question, I am just a beginner taking the 3.5 hour masterclass, But have one question. What is an instance. I saw one of the post and still didn’t get it, so someone like can put it in a shorter way so I can understand it.
Is it like class, struct, view something like that?
Someone else posted the same question as me and got replied. I checked that conversation reply which took me to a website. And at the website there still wasn’t anything to help me. So like what is an instance?
Like the actual thing not instance method. I didn’t’ t
really understand what Chris was saying in the video. So can you put it in a shorter way?
You have a type, which is essentially a template for something. A Person or a UIViewController or a Building or whatever.
An instance is one of those things.
Looking at some code:
//this is a TYPE
struct Person {
let firstname: String
let lastname: String
let address: CLLocation
}
//now we create an INSTANCE of that type
let girl = Person(firstname: "Charlotte",
lastname: "Grote",
address: CLLocation(latitude: 53.3814,
longitude: 1.4884))
An instance method is a function that applies to an instance of a type.
//this is an INSTANCE METHOD
extension Person {
func name() -> String {
"\(firstname) \(lastname)"
}
}
print(girl.name())
//Charlotte Grote