How to recognize swipe in all 4 directions

IosSwiftSwipeDirectionUiswipegesturerecognizer

Ios Problem Overview


I need to use swipe to recognize swipe gesture down and then right. But on swift UISwipeGestureRecognizer has predeterminate Right direction.. And I don't know how make this for use other directions..

Ios Solutions


Solution 1 - Ios

You need to have one UISwipeGestureRecognizer for each direction. It's a little weird because the UISwipeGestureRecognizer.direction property is an options-style bit mask, but each recognizer can only handle one direction. You can send them all to the same handler if you want, and sort it out there, or send them to different handlers. Here's one implementation:

override func viewDidLoad() {
    super.viewDidLoad()
    
    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
    swipeRight.direction = .right
    self.view.addGestureRecognizer(swipeRight)
    
    let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
    swipeDown.direction = .down
    self.view.addGestureRecognizer(swipeDown)
}

@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {

    if let swipeGesture = gesture as? UISwipeGestureRecognizer {

        switch swipeGesture.direction {
        case .right:
            print("Swiped right")
        case .down:
            print("Swiped down")
        case .left:
            print("Swiped left")
        case .up:
            print("Swiped up")
        default:
            break
        }
    }
}

Swift 3:

override func viewDidLoad() {
    super.viewDidLoad()
    
    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
    swipeRight.direction = UISwipeGestureRecognizerDirection.right
    self.view.addGestureRecognizer(swipeRight)
    
    let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
    swipeDown.direction = UISwipeGestureRecognizerDirection.down
    self.view.addGestureRecognizer(swipeDown)
}

func respondToSwipeGesture(gesture: UIGestureRecognizer) {
    if let swipeGesture = gesture as? UISwipeGestureRecognizer {
        switch swipeGesture.direction {
        case UISwipeGestureRecognizerDirection.right:
            print("Swiped right")
        case UISwipeGestureRecognizerDirection.down:
            print("Swiped down")
        case UISwipeGestureRecognizerDirection.left:
            print("Swiped left")
        case UISwipeGestureRecognizerDirection.up:
            print("Swiped up")
        default:
            break
        }
    }
}

Solution 2 - Ios

I just felt like contributing this, looks more elegant in the end:

func addSwipe() {
	let directions: [UISwipeGestureRecognizerDirection] = [.Right, .Left, .Up, .Down]
	for direction in directions {
		let gesture = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipe:"))
		gesture.direction = direction
		self.addGestureRecognizer(gesture)
	}
}

func handleSwipe(sender: UISwipeGestureRecognizer) {
	print(sender.direction)
}

Solution 3 - Ios

From the storyboard:

  1. Add four swipe gesture recognizers to your view.
  2. Set each one with the target direction from the attribute inspector. You can select right, left, up or down
  3. One by one, select the swipe gesture recognizer, control + drag to your view controller. Insert the name (let us say leftGesture, rightGesture, upGesture and downGesture), change the connection to: Action and type to: UISwipeGestureRecognizer

From your viewController:

@IBAction func rightGesture(sender: UISwipeGestureRecognizer) {
    print("Right")
}
@IBAction func leftGesture(sender: UISwipeGestureRecognizer) {
    print("Left")
}
@IBAction func upGesture(sender: UISwipeGestureRecognizer) {
    print("Up")
}

@IBAction func downGesture(sender: UISwipeGestureRecognizer) {
    print("Down")
}  

Solution 4 - Ios

Looks like things have changed lately. In XCode 7.2 the following approach works:

override func viewDidLoad() {
    super.viewDidLoad()

    let swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipe:")
    swipeGesture.direction = [.Down, .Up]
    self.view.addGestureRecognizer(swipeGesture)
}

func handleSwipe(sender: UISwipeGestureRecognizer) {
    print(sender.direction)
}

Tested in Simulator on iOS 8.4 and 9.2 and on actual device on 9.2.

Or, using mlcollard's handy extension here:

let swipeGesture = UISwipeGestureRecognizer() {
	print("Gesture recognized !")
}

swipeGesture.direction = [.Down, .Up]
self.view.addGestureRecognizer(swipeGesture)

Solution 5 - Ios

Apple Swift version 3.1 - Xcode Version 8.3 (8E162)

The handy way from [Alexandre Cassagne's approach][1]

let directions: [UISwipeGestureRecognizerDirection] = [.up, .down, .right, .left]
for direction in directions {
    let gesture = UISwipeGestureRecognizer(target: self, action: #selector(YourClassName.handleSwipe(gesture:)))
    gesture.direction = direction
    self.view?.addGestureRecognizer(gesture)   
}

func handleSwipe(gesture: UISwipeGestureRecognizer) {
    print(gesture.direction)
    switch gesture.direction {
    case UISwipeGestureRecognizerDirection.down:
        print("down swipe")
    case UISwipeGestureRecognizerDirection.up:
        print("up swipe")
    case UISwipeGestureRecognizerDirection.left:
        print("left swipe")
    case UISwipeGestureRecognizerDirection.right:
        print("right swipe")
    default:
        print("other swipe")
    }
}

[1]: https://stackoverflow.com/a/34076780/1362921 "Alexandre Cassagne"

Solution 6 - Ios

In Swift 4.2 and Xcode 9.4.1

Add Animation delegate, CAAnimationDelegate to your class

//Swipe gesture for left and right
let swipeFromRight = UISwipeGestureRecognizer(target: self, action: #selector(didSwipeLeft))
swipeFromRight.direction = UISwipeGestureRecognizerDirection.left
menuTransparentView.addGestureRecognizer(swipeFromRight)
    
let swipeFromLeft = UISwipeGestureRecognizer(target: self, action: #selector(didSwipeRight))
swipeFromLeft.direction = UISwipeGestureRecognizerDirection.right
menuTransparentView.addGestureRecognizer(swipeFromLeft)

//Swipe gesture selector function
@objc func didSwipeLeft(gesture: UIGestureRecognizer) {
    //We can add some animation also
    DispatchQueue.main.async(execute: {
            let animation = CATransition()
            animation.type = kCATransitionReveal
            animation.subtype = kCATransitionFromRight
            animation.duration = 0.5
            animation.delegate = self
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            //Add this animation to your view
            self.transparentView.layer.add(animation, forKey: nil)
            self.transparentView.removeFromSuperview()//Remove or hide your view if requirement.
        })
}

//Swipe gesture selector function
@objc func didSwipeRight(gesture: UIGestureRecognizer) {
        // Add animation here
        DispatchQueue.main.async(execute: {
            let animation = CATransition()
            animation.type = kCATransitionReveal
            animation.subtype = kCATransitionFromLeft
            animation.duration = 0.5
            animation.delegate = self
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            //Add this animation to your view
            self.transparentView.layer.add(animation, forKey: nil)
            self.transparentView.removeFromSuperview()//Remove or hide yourview if requirement.
        })
}

If you want to remove gesture from view use this code

self.transparentView.removeGestureRecognizer(gesture)

Ex:

func willMoveFromView(view: UIView) {
    if view.gestureRecognizers != nil {
        for gesture in view.gestureRecognizers! {
            //view.removeGestureRecognizer(gesture)//This will remove all gestures including tap etc...
            if let recognizer = gesture as? UISwipeGestureRecognizer {
                //view.removeGestureRecognizer(recognizer)//This will remove all swipe gestures
                if recognizer.direction == .left {//Especially for left swipe
                    view.removeGestureRecognizer(recognizer)
                }
            }
        }
    }
}

Call this function like

//Remove swipe gesture
self.willMoveFromView(view: self.transparentView)

Like this you can write remaining directions and please careful whether if you have scroll view or not from bottom to top and vice versa

If you have scroll view, you will get conflict for Top to bottom and view versa gestures.

Solution 7 - Ios

Swipe gesture to the view you want, or viewcontroller whole view in Swift 5 & XCode 11 based on @Alexandre Cassagne

override func viewDidLoad() {
    super.viewDidLoad()
    
    addSwipe()
}

func addSwipe() {
    let directions: [UISwipeGestureRecognizer.Direction] = [.right, .left, .up, .down]
    for direction in directions {
        let gesture = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe))
        gesture.direction = direction
        self.myView.addGestureRecognizer(gesture)// self.view
    }
}

@objc func handleSwipe(sender: UISwipeGestureRecognizer) {
    let direction = sender.direction
    switch direction {
        case .right:
            print("Gesture direction: Right")
        case .left:
            print("Gesture direction: Left")
        case .up:
            print("Gesture direction: Up")
        case .down:
            print("Gesture direction: Down")
        default:
            print("Unrecognized Gesture Direction")
    }
}

Solution 8 - Ios

UISwipeGestureRecognizer has a direction property that has the following definition:

var direction: UISwipeGestureRecognizerDirection

>The permitted direction of the swipe for this gesture recognizer.


The problem with Swift 3.0.1 (and below) is that even if UISwipeGestureRecognizerDirection conforms to OptionSet, the following snippet will compile but won't produce any positive expected result:

// This compiles but does not work
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(gestureHandler))
gesture.direction = [.right, .left, .up, .down]
self.addGestureRecognizer(gesture)

As a workaround, you will have to create a UISwipeGestureRecognizer for each desired direction.


The following Playground code shows how to implement several UISwipeGestureRecognizer for the same UIView and the same selector using Array's map method:

import UIKit
import PlaygroundSupport

class SwipeableView: UIView {
    convenience init() {
        self.init(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        backgroundColor = .red

        [UISwipeGestureRecognizerDirection.right, .left, .up, .down].map({
            let gesture = UISwipeGestureRecognizer(target: self, action: #selector(gestureHandler))
            gesture.direction = $0
            self.addGestureRecognizer(gesture)
        })
    }
    
    func gestureHandler(sender: UISwipeGestureRecognizer) {
        switch sender.direction {
        case [.left]:   frame.origin.x -= 10
        case [.right]:  frame.origin.x += 10
        case [.up]:     frame.origin.y -= 10
        case [.down]:   frame.origin.y += 10
        default:        break
        }
    }
}

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        view.addSubview(SwipeableView())
    }
}

let controller = ViewController()
PlaygroundPage.current.liveView = controller

Solution 9 - Ios

Swipe Gesture in Swift 5

  override func viewDidLoad() {
    super.viewDidLoad()
    let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeLeft.direction = .left
    self.view!.addGestureRecognizer(swipeLeft)
    
    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeRight.direction = .right
    self.view!.addGestureRecognizer(swipeRight)
    
    let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeUp.direction = .up
    self.view!.addGestureRecognizer(swipeUp)
    
    let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture))
    swipeDown.direction = .down
    self.view!.addGestureRecognizer(swipeDown)
}

@objc func handleGesture(gesture: UISwipeGestureRecognizer) -> Void {
    if gesture.direction == UISwipeGestureRecognizer.Direction.right {
        print("Swipe Right")
    }
    else if gesture.direction == UISwipeGestureRecognizer.Direction.left {
        print("Swipe Left")
    }
    else if gesture.direction == UISwipeGestureRecognizer.Direction.up {
        print("Swipe Up")
    }
    else if gesture.direction == UISwipeGestureRecognizer.Direction.down {
        print("Swipe Down")
    }
}

Solution 10 - Ios

EDİT: "swift5.3"

First create a baseViewController and add viewDidLoad this code :

class BaseViewController: UIViewController {             

     override func viewDidLoad() {
         super.viewDidLoad()
          let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
          swipeRight.direction = .right
          self.view.addGestureRecognizer(swipeRight)
          let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
          swipeLeft.direction = .left
          self.view.addGestureRecognizer(swipeLeft)
     }

     // Example Tabbar 5 pages
     @objc func swiped(_ gesture: UISwipeGestureRecognizer) {
         if gesture.direction == .left {
            if (self.tabBarController?.selectedIndex)! < 5 {
                self.tabBarController?.selectedIndex += 1
            }
         } else if gesture.direction == .right {
             if (self.tabBarController?.selectedIndex)! > 0 {
                 self.tabBarController?.selectedIndex -= 1
             }
         }
     }  
}

And use this baseController class:

class YourViewController: BaseViewController {
    // its done. Swipe successful
    //Now you can use all the Controller you have created without writing any code.    
}

Solution 11 - Ios

In Swift 5,

let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe))
swipeGesture.direction = [.left, .right, .up, .down]
view.addGestureRecognizer(swipeGesture)

Solution 12 - Ios

After digging around for a while:

The shortest way to add swipes for all 4 directions is:

override func viewDidLoad() {
    super.viewDidLoad()    
    for direction in [UISwipeGestureRecognizer.Direction.down, .up, .left, .right]{
        let swipeGest = UISwipeGestureRecognizer(target: self, action: #selector(swipeAction(_:)))
        swipeGest.direction = direction
        self.view.addGestureRecognizer(swipeGest)
    }
} 
    
@objc func swipeAction(_ gesture: UISwipeGestureRecognizer){
    switch gesture.direction {
    case UISwipeGestureRecognizer.Direction.right:
        print("Swiped right")
    case UISwipeGestureRecognizer.Direction.down:
        print("Swiped down")
    case UISwipeGestureRecognizer.Direction.left:
        print("Swiped left")
    case UISwipeGestureRecognizer.Direction.up:
        print("Swiped up")
    default: break
}

Solution 13 - Ios

Just a cooler swift syntax for Nate's answer:

[UISwipeGestureRecognizerDirection.right,
 UISwipeGestureRecognizerDirection.left,
 UISwipeGestureRecognizerDirection.up,
 UISwipeGestureRecognizerDirection.down].forEach({ direction in
    let swipe = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
    swipe.direction = direction
    self.view.addGestureRecognizer(swipe)
 })

Solution 14 - Ios

Easy. Just follow the code below and enjoy.

//SwipeGestureMethodUsing
func SwipeGestureMethodUsing ()
{
    //AddSwipeGesture
    [UISwipeGestureRecognizerDirection.right,
     UISwipeGestureRecognizerDirection.left,
     UISwipeGestureRecognizerDirection.up,
     UISwipeGestureRecognizerDirection.down].forEach({ direction in
        let swipe = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
        swipe.direction = direction
        window?.addGestureRecognizer(swipe)
     })
}

//respondToSwipeGesture
func respondToSwipeGesture(gesture: UIGestureRecognizer) {
    
    if let swipeGesture = gesture as? UISwipeGestureRecognizer
    {
        switch swipeGesture.direction
        {
        case UISwipeGestureRecognizerDirection.right:
            print("Swiped right")
        case UISwipeGestureRecognizerDirection.down:
            print("Swiped down")
        case UISwipeGestureRecognizerDirection.left:
            print("Swiped left")
        case UISwipeGestureRecognizerDirection.up:
            print("Swiped up")
        default:
            break
        }
    }
}

Solution 15 - Ios

It can be done by simply declaring one function which will handle all your swipe UISwipeGestureRecognizer directions. Here is my code:

let swipeGestureRight = UISwipeGestureRecognizer(target: self, action:#selector(ViewController.respondToSwipeGesture(_:)) )
swipeGestureRight.direction = UISwipeGestureRecognizerDirection.right
self.view .addGestureRecognizer(swipeGestureRight)

let swipeGestureLeft = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.respondToSwipeGesture(_:)))
swipeGestureLeft.direction = UISwipeGestureRecognizerDirection.left
self.view.addGestureRecognizer(swipeGestureLeft)

let swipeGestureUp = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.respondToSwipeGesture(_:)))
swipeGestureUp.direction = UISwipeGestureRecognizerDirection.up
self.view.addGestureRecognizer(swipeGestureUp)

let swipeGestureDown = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.respondToSwipeGesture(_:)))
swipeGestureDown.direction = UISwipeGestureRecognizerDirection.down
self.view.addGestureRecognizer(swipeGestureDown)

Here is the function which will hande the swipedirection functionality:

func respondToSwipeGesture(_ sender: UIGestureRecognizer) {
	if let swipeGesture = sender as? UISwipeGestureRecognizer {
		switch swipeGesture.direction {
			case UISwipeGestureRecognizerDirection.right:
				print("right swipe")
			case UISwipeGestureRecognizerDirection.left:
				print("leftSwipe")
			case UISwipeGestureRecognizerDirection.up:
				print("upSwipe")
			case UISwipeGestureRecognizerDirection.down:
				print("downSwipe")
			default:
				break
		}
	}
}

Solution 16 - Ios

Just like that: (Swift 4.2.1)

UISwipeGestureRecognizer.Direction.init(
  rawValue: UISwipeGestureRecognizer.Direction.left.rawValue |
            UISwipeGestureRecognizer.Direction.right.rawValue |
            UISwipeGestureRecognizer.Direction.up.rawValue |
            UISwipeGestureRecognizer.Direction.down.rawValue
)

Solution 17 - Ios

For Swift 5 it's updated

//Add in ViewDidLoad
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.handleSwipe))
        gesture.direction = .right
        self.view.addGestureRecognizer(gesture)

//Add New Method
@objc func handleSwipe(sender: UISwipeGestureRecognizer) {
        print("swipe direction is",sender.direction)
        
    }

Solution 18 - Ios

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let leftside = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
        leftside.direction = .left
        view.addGestureRecognizer(leftside)
        
        let rightside = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
        rightside.direction = .right
        view.addGestureRecognizer(rightside)
        
        
        let upside =  UISwipeGestureRecognizer(target: self, action: #selector(swiped))
        upside.direction = .up
        view.addGestureRecognizer(upside)
        
        let downside = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
        downside.direction = .down
        view.addGestureRecognizer(downside)
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    @objc func swiped(gesture: UIGestureRecognizer){
        if let swipeGesture = gesture as? UISwipeGestureRecognizer{
            switch swipeGesture.direction{
            case UISwipeGestureRecognizer.Direction.left:
                view.backgroundColor = UIColor.red
            case UISwipeGestureRecognizer.Direction.right:
                view.backgroundColor = UIColor.yellow
            case UISwipeGestureRecognizer.Direction.up:
                view.backgroundColor = UIColor.green
            case UISwipeGestureRecognizer.Direction.down:
                view.backgroundColor = UIColor.blue
               
            default:
                "ERROR"
                
            }
        }
    }

}

Solution 19 - Ios

i found the simple way for recognise gesture with swift 5 and xcode 13

     let gestureLeft = UISwipeGestureRecognizer(target: self, action: #selector(onLeftGesture))
    gestureLeft.direction = UISwipeGestureRecognizer.Direction.left
    imageView.addGestureRecognizer(gestureLeft)
    
    let gestureRight = UISwipeGestureRecognizer(target: self, action: #selector(onRightGesture))
    gestureRight.direction = .right
    imageView.addGestureRecognizer(gestureRight)
    
    let gestureUp = UISwipeGestureRecognizer(target: self, action: #selector(onUpGesture))
    gestureUp.direction = .up
    imageView.addGestureRecognizer(gestureUp)
    
    let gestureDown = UISwipeGestureRecognizer(target: self, action: #selector(onDownGesture))
    gestureDown.direction = .down
    imageView.addGestureRecognizer(gestureDown)
            
    let gestureTapSingle = UITapGestureRecognizer(target: self, action: #selector(onSingleTapGesture))
    gestureTapSingle.numberOfTapsRequired = 1
    labelGesture.addGestureRecognizer(gestureTapSingle)
    
    let gestureTapDouble = UITapGestureRecognizer(target: self, action: #selector(onDoubleTapGesture))
    gestureTapDouble.numberOfTapsRequired = 2
    labelGesture.addGestureRecognizer(gestureTapDouble)
    
    gestureTapSingle.require(toFail: gestureTapDouble)
    
    let gesturePressLong = UILongPressGestureRecognizer(target: self, action: #selector(onLongPressGesture))
    gesturePressLong.minimumPressDuration = 0.5
    labelGesture.addGestureRecognizer(gesturePressLong)
}
@objc func onLeftGesture(_ sender: UISwipeGestureRecognizer) {
    print("Left")
}

@objc func onRightGesture(_ sender: UISwipeGestureRecognizer) {
    print("Right")
}

@objc func onUpGesture(_ sender: UISwipeGestureRecognizer) {
    print("Up")
}

@objc func onDownGesture(_ sender: UISwipeGestureRecognizer) {
    print("Down")
}
    
@objc func onSingleTapGesture(_ sender: UITapGestureRecognizer) {
 print("Single Tap")
}

@objc func onDoubleTapGesture(_ sender: UITapGestureRecognizer) {
   print("Double Tap")
}

@objc func onLongPressGesture(_ sender: UILongPressGestureRecognizer) {
   print("Long Press Gesture!!!")
}


Solution 20 - Ios

Swift 5+

Add desired gestures to some UIView:

[UISwipeGestureRecognizer.Direction.up, .down, .left, .right].forEach {
    let gesture = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
    gesture.direction = $0
    someView.addGestureRecognizer(gesture)
}

Handle swipe actions:

@objc func swiped(_ gesture: UISwipeGestureRecognizer) {
    switch gesture.direction {
    case .up:       print("up")
    case .down:     print("down")
    case .left:     print("left")
    case .right:    print("right")
    default: break
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3739367View Question on Stackoverflow
Solution 1 - IosNate CookView Answer on Stackoverflow
Solution 2 - IosAlexandre CassagneView Answer on Stackoverflow
Solution 3 - Iosuser3099333View Answer on Stackoverflow
Solution 4 - IosBogdan FarcaView Answer on Stackoverflow
Solution 5 - IosJohannes KnustView Answer on Stackoverflow
Solution 6 - IosNareshView Answer on Stackoverflow
Solution 7 - IosEgzon P.View Answer on Stackoverflow
Solution 8 - IosImanou PetitView Answer on Stackoverflow
Solution 9 - IosLijith VipinView Answer on Stackoverflow
Solution 10 - IosikbalView Answer on Stackoverflow
Solution 11 - Iosnitin.agamView Answer on Stackoverflow
Solution 12 - IosNeonGlossView Answer on Stackoverflow
Solution 13 - IosAmitPView Answer on Stackoverflow
Solution 14 - IosSuper DeveloperView Answer on Stackoverflow
Solution 15 - IosShaktiView Answer on Stackoverflow
Solution 16 - IosjeudespritsView Answer on Stackoverflow
Solution 17 - IosswiftBoyView Answer on Stackoverflow
Solution 18 - IosmAjView Answer on Stackoverflow
Solution 19 - IosSavan italiya rangholaView Answer on Stackoverflow
Solution 20 - IosbudiDinoView Answer on Stackoverflow