Skip to content

Swift Refactoring #1: Implement methods

Creating handmade mocks is a common task many of us have to suffer through in Swift. The last thing we want to do is write is more boiler plate code.

Xcode gives us some help; if we start typing the name of the method, Xcode can autocomplete it for us. But this can take ages for larger protocols. And who wants to jump back and forth between the protocol and the mock to remember the name of each method?

This AppCode moment is dedicated to the Implement methods action.

Menu itemCode → Implement methods...

All your protocol methods are implemented in one fell swoop.

Implement methods example

Extra tips

  • It also adds a return statement when it can.
  • If you already have implemented some of the protocol methods, it only adds the missing ones.
  • It supports multiple protocols and inherited protocols.
  • You can be selective about which methods to adopt; useful for delegates with optional protocol methods from Objective-C.
  • Override methods (^⌘O) does the same but (you guessed it) suggests methods to override from superclasses.

Subscribe now to hear more about AppCode tips and tricks

Published inAppCodeEssential tips you didn't know that will make you ditch XcodeSwift refactoring with AppCode

Be First to Comment

Leave a Reply