Skip to content

Instantly share code, notes, and snippets.

@abhimuralidharan
Created March 15, 2019 04:04
Show Gist options
  • Save abhimuralidharan/0c431cd0007cb915296e62909c85cfbe to your computer and use it in GitHub Desktop.
Save abhimuralidharan/0c431cd0007cb915296e62909c85cfbe to your computer and use it in GitHub Desktop.
class A{
class func classFunction(){
}
static func staticFunction(){
}
class func classFunctionToBeMakeFinalInImmediateSubclass(){
}
}
class B: A {
override class func classFunction(){
}
//Compile Error. Class method overrides a 'final' class method
override static func staticFunction(){
}
//Lets avoid the function called 'classFunctionToBeMakeFinalInImmediateSubclass' being overriden by subclasses
/* First way of doing it
override static func classFunctionToBeMakeFinalInImmediateSubclass(){
}
*/
// Second way of doing the same
override final class func classFunctionToBeMakeFinalInImmediateSubclass(){
}
//To use static or final class is choice of style.
//As mipadi suggests I would use. static at super class. and final class to cut off further overrides by a subclass
}
class C: B{
//Compile Error. Class method overrides a 'final' class method
override static func classFunctionToBeMakeFinalInImmediateSubclass(){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment