Technical Design of QuickFileCompare

From Acacia Support Wiki
Jump to navigation Jump to search

SwiftUI

This app is based as much as possible on SwiftUI. This is a great improvement to Apple software development and probably saves 95% of the code required to produce the user interface for an App.

After experience developing KayakNav using Objective-C, Swift is another amazing improvement to the volume of code, complexity etc to acheive the same result. Development is so fast and accurate due to all the intellisense, colour highlighting and error checking, the code just works and avoids common run time problems.

Loading Files

Support for drag'n'drop onto the left and right comparison areas. This was simple to add in SwiftUI and avoids any special code to handle permissions and file dialogues.

Filter Options

When files are loaded, the content is held in variables and processed into the final comparison. This allows filtering to remove blank lines, capitalise etc to be applied and changed as required by checking boxes at the top of the screen.

Comparing Files

The foundation library provide simple difference and apply functions that in theory should make an App like this a no-brainer to develop, but the devil is in the detail.

Based on Version Control

Given the built in functions and existing software version tracking systems, the design began based on developing a simple version control system. File A is checked in, then checked out again and replaced with file B. The differences are then extracted and a side-by-side comparison. Simple ... or maybe not!

Parsing

The difference method can be applied to sets of objects such as [String] or [Character] which results in a list of remove and insert operations that will generate File B when applied to to File A.

It took many iterations to settle on using [String] as the basis of the comparisons. The next step is converting the text only in File A into an appropriate array of String values for comparison. Simple splits by white space characters (new line, tab space etc) doesn't really work because the seperators disappear into the gaps between the array elements. These extra bits are important when creating and displaying the differences. The parsing process ended up using regular expressions that retained the seperators including punctuation.

Using the array generated from File A, we duplicate it to a RHS array and work through the difference remove/insert instructions. In the process, the array elements are tagged for highlighting.

Preparing the Results

The final step in the comparison is generating the side-by-side text. This is done by reconstructing the LHS and RHS text from the arrays of words based on the difference results. Because all of the words, white space and punctuation are retained, the text can be reconstructed just by joining the arrays.

Attributed Strings are perfect for the presentation of the final results. The can be composed of multiple sections each with their own fonts, colours and styles. The LHS and RHS comparisons are reconstitued from differences as Attributed strings.

Presenting the Results

SwiftUI offers may options with scroll views, lists, splitters etc etc. It was decided to place a scroll view over the LHS and RHS and line number areas so that they scroll together.

Performance

All unnecessary code and processing has been eliminated to ensure fast processing of large files.

Help Screens

The use of "Help Books" for Mac apps has been avoided in this app. Instead, a help button on the main form takes you straight to this wiki which is simpler to update as needed.