------------------------///* Note: 1: Static function can not inherit 2: The protocol is not the same as OC, although there are optional and required keywords, but not good to make a ~ The static function (+) inside the 3:OC protocol can override Override,swift, prompting for the final function. Or Swift is better, more rigorous. In the 4:convenience constructor, it is not possible to use the form of self+. Init to play out, thought not to support it, the result of direct writing is no problem. But self cannot be omitted. The 5:convenience function cannot override the override 6: a function that changes member variables within a class without mutating modification, structure, and enumeration required. But the compiler has a hint, very convenient ~. 7: If the subclass also declares a function that is the same as the parent class, the compiler has to let the add-override,oc be overwritten. This is not the same as Delphi. @protocol classprotocol <NSObject> @required + (nsstring*) classdescription; -(nsstring*) Description; @end/* Do not declare, the direct implementation of the line ~*/@interface classtestbase:nsobject<classprotocol> + (nsstring*) classdescription; @end @interface classtestchild:classtestbase @end @implementation classtestbase + (nsstring*) classdescription{ret Urn @ "This is a class-based static function"; }-(nsstring*) description{return @ "This is a class-based member function";} @end @implementation Classtestchild-(nsstring*) description{ Return @ "This is a member function of class subclass"; } + (nsstring*) classdescription{return @ "This is a class subclass of static function";} @end @implementation Viewcontroller-(void) Viewdidload {[Super Viewdidload]; classtestbase* c = [[Classtestchild alloc] init]; NSLog (@ "%@:%@", C.description,[classtestchild classdescription]); }*/protocol Classprotocol {static func classdescription ()->string func Description () String}class classtes tbase:classprotocol{static func classdescription () String {return "This is a class-based static function"} var truename : string= "" var id:int = 0; Private init (atruename:string,aid:int) {self. Truename = Atruename self.id = AID; } convenience init (atruename:string) {self.init (Atruename:atruename, AID:-1)} func Description () String {return "This is a member function of class base class"} Func Addmyid (), Void {ID + = 1}}class classtestchild : classtestbase {override func Description () String {return "This is a member function of class subclass"} Override Init (Atru Ename:string, Aid:int) {super.init (Atruename:atruename, aid:aid) super.id = AID + 5; } ConveniencE init (atruename:string) {self.init (Atruename:atruename, AID:-2)} override Func Addmyid (), Void { Super. Addmyid () id+=1}}let obj:classtestbase = Classtestchild (atruename: "Hello") obj. Addmyid () print (obj.id)The usage of the class is far more than these, today is only preliminary write down, later encountered what problems to change ~
[Swift Learning five] type of exercise