Ios Notlar
Swift Genel Notlar
Bu post içerisinde swiftle alakalı kategorize etme gereği duymadığım genel notları paylaşacağım. Bu post bir daha hiç editlenmeyebilir, büyüdükçe kategorize edilip parçalanabilir veya aynı böyle devam edebilir.
SWIFT Syntax Olayları :
- var ve let farkı : let constant yapar.
- variable’a type atamak :
var numOfSeats : Int = 3
- CONSTRUCTORS
class Car {
var colour = "Red"
var numOfSeats : Int = 3
var carType : CarType = .Scoda
init(customerChosenColour:String) {
colour = customerChosenColour
}
}
- Bu tip bir constructor deklerasyonu kullanırsak obje oluştururken parametreleri vermemiz zorunludur.
class Car {
var colour = "Red"
var numOfSeats : Int = 3
var carType : CarType = .Scoda
init() {
}
convenience init(customerChosenColour:String) {
self.init() // init constructoruyla kopya oluşturur
colour = customerChosenColour
}
func drive() {
print(self.colour)
}
}
- convenience initializer kullanırsak parametre vermek veya vermemek isteğe bağlı oluyor.
-
Convenience initializer içerisinde “self.init()” yazılmak zorundadır.
- INHERITANCE AND OVERRIDING FUNCTIONS
class Car {
var colour = "Red"
var numOfSeats : Int = 3
var carType : CarType = .Scoda
init() {
}
convenience init(customerChosenColour:String) {
self.init() // init constructoruyla kopya oluşturur
colour = customerChosenColour
}
func drive() {
print(self.colour)
}
}
class SelfDrivingCar : Car {
override func drive() {
print(self.numOfSeats)
}
}
Leave a comment