I’d suggest integrating Periphery in your CI pipeline or running it manually every 3-6 months. There is no reason to keep dead code in your project, it needs to be found and removed. Due to this, it provides quite accurate results that might be used in further considerations. Periphery implementation is based on SourceKit framework that helps finding the references between declarations.
Periphery will start a guided setup, resulting in printing out the full scan command and executing one.
You can install one easily via homebrew: brew tap peripheryapp/peripheryĪfter installation is complete, run the following command: periphery scan Periphery is an open-source tool written in Swift that aims to find unused declarations in your code. Removing unused declarations with Periphery So, it makes sense to verify the script’s output before doing a cleanup. Unfortunately, you might get lots of false-positive results because the script just performs text search under the hood. You can follow this list to remove unused code from your project. You can install it by cloning the repository and run via command line from the project’s directory: cd Īs a result of running the script you will get a list of items: Imported libraries are integrated using cocoapods into my workspace. I can't get any suggestios I would get in XCode. Project builds fine, both xcode and appcode. Swift-scripts is an open-source repository available on Github that comes with a script written in Ruby. Using latest AppCode 3.3.2 Not sure whether I've missed something but code completion for imported frameworks ( cocoapods ) doesnt works. Cleaning up unused code with Swift-scripts This way you can get a warning about some of the unused declarations in your code. It might be useful to turn on compiler warning flags like -Wunused-variable, -Wunused-label, etc. You can adjust AppCode introspection options via application preferences. It can help you find unused import directives as well.
AppCode works better with Objective-C code, detecting automatically unused code and suggesting the “Safe delete” quick-fix. Unfortunately, both IDEs don’t provide that many options to find unreachable code written in Swift.
Xcode and AppCode are designed to be a default tool that helps you keep your code accurate and clean. In this article I’ll go over a few tools which you can use to clean up your project:įinding unused code with Xcode and AppCode
Therefore, it’s useful to know how to find and remove unused code from your project. In the Preferences dialog, click Add Ruby SDK, and specify the path. The CocoaPods menu item is grayed out while the project is being indexed. Alternatively, in the Preference dialog S, go to Tools CocoaPods. Select Tools CocoaPods Select Ruby SDK from the main menu. Apart from cluttering the project, it might have an impact on a project’s build time by slowing it down. Download the iOSConferences project and open it in AppCode. On Swift Wings All posts Tags About Unused code cleanup in iOS projectsĪs your project evolves there might appear unreachable code that is not used anymore or will never be reached.