Swift: How to create iOS Today extension and share data with containing app

Do you happen had a chance to see the 3d touch icon widget or iOS Today Extension, let’s take a look at how to create an Extension in swift, how to open containing app and how to share data with containing app.

To add Today Extension to the project click “file” -> “new” -> “target”: chose “Today Extension”.
Let’s go to “Capabilities” tab and enable “App Groups” for both AppWithExtension and Extension targets, for both app and extension you need to click “+” icon under the “App Groups” and add Groups to you app id, e.g. like here

Continue reading “Swift: How to create iOS Today extension and share data with containing app”

Social Share Toolbar

Swift: how to use 3D Touch – Introduction

3D Touch or force touch – is a new feature that have been introduced in the iPhone 6s. It’s interesting to know that you can get touch force, it is a number from 0 up to 6.6667, actually it a number from 0 up to maximumPossibleForce.

Let’s take a look at how to check if 3d touch is supported on current device:

func is3dTouchAvailable(traitCollection: UITraitCollection) -> Bool {
    return traitCollection.forceTouchCapability == UIForceTouchCapability.available
// Let's call it somewhere from the GameScene for instance
override func didMove(to view: SKView) {
    if(is3dTouchAvailable(traitCollection: self.view!.traitCollection)) {

Feel free to take a look at the example project – I’ll provide the link in the end of this post.
So this is a good practice to check whether 3d touch is supported or not.

Here’s an example of how to get the force of the 3d touch

func touchMoved(touch: UITouch, toPoint pos: CGPoint) {
    let location = touch.location(in: self)
    let node = self.atPoint(location)
    if is3dTouchEnabled {
        bubble.setPressure(pressurePercent: touch.force / touch.maximumPossibleForce)
    } else {
        // It is important to use touchMoved for iPhones w/o 3dTouch,
        // So we can "emulate" it.
        bubble.setPressure(pressurePercent: 1)

The current value of the Touch’s force is touch.force and the touch.maximumPossibleForce is a good one to convert force value to the “percentage”.
This code is from the small example of how to “emulate” the bubble reacting on the force of the touch.
To try this on your iPhone 6s/7 you can install this bubble wrap app real quick.

Here is my previous post with more details about Haptic feedback.

Social Share Toolbar