Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

abstract class in swift

class Animal {
    func sound() {}
}

class Cat: Animal {
    override func sound() {
        print("miauw")
    }
}

class Dog: Animal {
    override func sound() {
        print("woof")
    }
}
Comment

Abstract classes in Swift

protocol Employee {
    var annualSalary: Int {get}
}

extension Employee {
    var biweeklySalary: Int {
        return self.annualSalary / 26
    }

    func logSalary() {
        print("$(self.annualSalary) per year or $(self.biweeklySalary) biweekly")
    }
}

struct SoftwareEngineer: Employee {
    var annualSalary: Int

    func logSalary() {
        print("overridden")
    }
}

let sarah = SoftwareEngineer(annualSalary: 100000)
sarah.logSalary() // prints: overridden
(sarah as Employee).logSalary() // prints: $100000 per year or $3846 biweekly
Comment

PREVIOUS NEXT
Code Example
Swift :: swft view 
Swift :: add arc swiftui 
Swift :: swift switch statement 
Swift :: variable sum in swift 
Swift :: Swift How to declare an optional in Swift? 
Swift :: swift wait until condition is true 
Swift :: Swift Create String Instance 
Swift :: send receive udp swift 
Swift :: does swift language requires mac os system 
Swift :: Customize indicator view iOS swift 
Swift :: swift ns_enum generic name 
Swift :: editbutton swiftui color text 
Swift :: command compileswift failed with a nonzero exit code 
Swift :: implement swift protocol in kotlin 
Swift :: swift multiline comment 
Swift :: array of button listeners swift 
Swift :: Swift Explicitly declaring an unwrapped optional 
Swift :: swift api call certificate 
Swift :: Function Call Using try Keyword Swift 
Swift :: AndroidManifest.xml:5: Error: Class referenced in the manifest flutter build 
Swift :: octobercms add extra slash to css url 
Swift :: ios network request 
Swift :: move to nect cell of collection after some time automatically in ios swift 
Ruby :: rails remove column from model 
Ruby :: get current year in ruby 
Ruby :: ruby min 2 numbers 
Ruby :: head in rails 
Ruby :: rails form fields 
Ruby :: smallest base64 image string 
Ruby :: new line in ruby 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =