Store origin position from image array for later function call

Hi everyone,

I already have a solution to save the origin position of an image and let it go back to this position when the image is not placed on the correct field. However, it’s complicated when I have a collection of images. This is why I wanted to implement an array for my set of images to loop through and associate a CGPOINT coordinate to each image.

However, my problem is, that I have a collection of images where I would like to achieve the same functionality. I think the best way is to save the images in an array. But I don’t know how to also associate the origin position to these array images. I thought of a solution like:

VIEW CONTROLLER

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var correctField1: UIImageView!
    @IBOutlet weak var correctField2: UIImageView!
    @IBOutlet weak var image1: UIImageView!
    @IBOutlet weak var image2: UIImageView!

    var imageOrigin = Image()
    
    override func viewDidLoad() {
        super.viewDidLoad()

            imageOrigin.setPositionOrigin([image1, image2])
    }
    
    @IBAction func handlePan(sender:UIPanGestureRecognizer) {
        
        let translation = sender.translationInView(self.view)
        
        if let view = sender.view {
            view.center = CGPoint(x:view.center.x + translation.x,
                                  y:view.center.y + translation.y)
            sender.setTranslation(CGPointZero, inView: self.view)
            
        }
        
        if sender.state == UIGestureRecognizerState.Ended {
        
        image1.center = imageOrigin.getPositionOrigin()
        
        }
    }
}

IMAGE CLASS

import UIKit

class Image: UIImageView {
    

    var Images: [UIImageView]!
    var positionOrigin: CGPoint!
    
    func setPositionOrigin(Images: [UIImageView]!) {
        var i = 0
        for image in Images {
            positionOrigin = image.center
            i += 1
        }
    }
    func getPositionOrigin() -> CGPoint {
        
        return positionOrigin
    }

}

But I always get a compiler error “Thread 1: breakpoint 1.4” at var imageOrigin = Image().

Does anyone know what to do, if I want to

  1. Save the origin position of each image in an array (cf. imageOrigin.setPositionOrigin([image1, image2])), while
  2. calling the origin position of each image in a second step (cf. image1.center = imageOrigin.getPositionOrigin())?