Auto generate swift protocol placeholders in implementation class

Hi


After I create a protocol I typically create concrete implmentation of the protocol.

Xcode will say you have not implmented the "required" protocol methods in the implementation class, "clas does not conform to protocol:"


Would it be possible to add a feature to Xcode where it will automatically generate "dummy" implmentations for the missing "required" protocol methods, a "Fix-It" type hint feature.


In the eclipse Java IDE there is "fix-it" type feature "Add unimplmented methods" and generates dummy implementations which allows you to focus on the minmal methods you need to get implemented to get the app compiling and running.

More annoyingly, clients of the class will also complain, so you can't clean-compile other files until you've actually implemented the protocol.


As a workaround, would it work for you to write the dummy implementations in a protocol extension? That would get rid of the errors, and you could copy and paste from there to your actual classes when you want to finish implementing them. Later on in the development cycle, you can delete the protocol extension, and then you'll get errors for anything you've missed.

Below is an example of the Xcode feature I was thinking of.


protocol SomeProto {

func returnInt() -> Int

func returnString() -> String

func returnValueType() -> CGRect

func returnADT() -> [String]

func returnOptionalClass() -> NSDateFormatter?

func returnClass() -> NSDateFormatter

}


X-Code would complain it does not conform to protocol)

class SomeProtoImpl : SomeProto {

}


Using Xcode new "Fix-it" feature it would generate default(dummy) implementations as depcited

below of the "required" protocol functions making SomeProtoImpl compile and then you replace

the dummy logic with the actual logic you would like to implement.


class SomeProtoImpl : SomeProto {

func returnInt() -> Int { return 0 }

func returnString() -> String { return "" }

func returnValueType() -> CGRect {return CGRectZero}

func returnADT() -> [String] { return []}

func returnOptionalClass() -> NSDateFormatter? { return nil}

func returnClass() -> NSDateFormatter { return NSDateFormatter() }

}

Please use the Report Bugs link at the bottom of the page to submit feature requests. The squeaky wheel gets the grease.

Done, #21416205

Auto generate swift protocol placeholders in implementation class
 
 
Q