The developers at FlexMonkey have written code in Swift to weigh plums using 3D Touch on an iPhone 6s.
Their latest app, called Plum-O-Meter, allows you to place two plums on the iPhone’s screen and will highlight the heavier of the two in yellow. The code behind the app is actually quite simple.
When the plum is placed on the screen, the app adds a new CircleWithLabel (which draws a circle with a label) to its view’s layer for each touch. This layer is then added to a dictionary with the touch as the key. The amount of force produced by the plum is used to control the new layer’s radius, which is displayed in the label.
If the plums move at any point, the touchesMoved function is used to readjust the position of the CircleWithLabel layer. The other key function in the code is the one which highlights the heaviest plum by figuring out which object is producing the greatest force on the display.
The iPhone 6s is not going to replace a high precision electronic scale anytime soon, however it is interesting to see what can be done with 3D Touch. The developers at FlexMonkey originally intended the app to work for grapes, however, they are too light to activate the 3D Touch sensors.
The source code for the Plum-O-Meter is available on GitHub if you are interested in giving it a try.