Pengetahuan umum iOS
1. Perbedaan Struct & Class
Class jenisna reference type,
maksudna, mun nga-assign instance class kana variable, variable na bakal tetep nga-refer ka instance na, lain copy, conto
class Employee {
var type: String
}
let roger = Emloyee(type: "fulltime")
let asep = roger
print(roger.type) // prints "fulltime"
print(asep.type) // prints "fulltime"
roger.type = "part time"
print(asep.type) // prints "part time"
mun Struct jenisna value type,
maksudna ngan copy tanpa nga-refer ka instance nu saacana, jadi mun struct instance awalna di modif, value anu kopianna mah tetep, contona
struct Employee {
var type: String
}
let roger = Emloyee(type: "fulltime")
let asep = roger
print(roger.type) // prints "fulltime"
print(asep.type) // prints "fulltime"
roger.type = "part time"
print(asep.type) // prints "fulltime" -> ieu tetep
Pros & Cons
Struct bagus jang model, karena teu nga-point ka hiji reference,
tapi Struct teu bisa inherit ka Struct lain
mun Class bisa inharitance ka Class lain, jadi cocok jang nyieun controller