An Xcode file template that generates multiple files with boilerplate code required for setting up a scene using VIPER and Coordinators.
- Clone this repository
cd
to it in Terminal- Change permissions and run the install script
chmod 755 install.sh && ./install.sh
Go to /Library/Developer/Xcode/Templates/File Templates and delete the ones you don't need anymore.
- Open your Xcode project
- Create a new file (
Cmd + N
) - Notice VIPER Coordinators in the left pane
Various current and previous issues and how to fix them.
In all versions up to version 1.5.0 (not including) there was a memory leak due to a retain cycle between the presenter and the coordinator.
This is the entire retain cycle:
Coordinator
> Navigation Controller
> View Controller
> Presenter
> Coordinator
The steps to fix this are as follows:
- Make the
YourCoordinatorInput
protocol a class protocol by appending: class
to its declaration - Change the coordinator reference in the presetner (the property) to be a weak reference, ie.
weak var coordinator: YourCoordinatorInput?
- Update all code in presenter referencing coordinator with
?
to fix issues with the property now being optional
To do all steps faster and automatically you can use Xcode's search and replace with regular expressions as follows:
Step 1
Search field: protocol ([\w]*)CoordinatorInput \{
Replace field: protocol $1CoordinatorInput: class \{
Step 2
Search field: let coordinator: ([\w]*)CoordinatorInput
Replace field: weak var coordinator: $1CoordinatorInput?
Step 3 (experimental, might need tweaks)
Search field: ([\n]+[\s]*coordinator)\.(?!start)
Replace field: $1?\.
Check it out HERE to see how we use this awesome pattern!
Made with ❤️ at Nodes.
VIPER Coordinators Xcode File Template is available under the MIT license. See the LICENSE file for more info.