Convert String to Integer (calculator app)
You had the right idea to use to encapsulate the variables and operations in a class object or struct, rather than using the global scope. It was not clear why this did not work for you.

To make things easy you can declare the object in the same file as the view controller.

E.g.

// Declare a struct to encapsulate the x and y variables.
// Perform the add and subtract operations using the instance variables.
// This code can be moved into Arithmetic.swift
struct Arithmetic {
   let x: Int
   let y: Int

   // Create a convenience initialiser for code which can be reused.
   init(x: String, y: String) {
       self.x = Int(x) ?? 0
       self.y = Int(y) ?? 0
   }

   // Use encapsulation to perform the operations.

   func add() -&gt; Int {
       return x + y
   }

   func subtract() -&gt; Int {
       return x - y
   }
}

class ViewController: UIViewController {

    // You correctly defined the IBOutlets as weak to prevent retain cycles.
    // Property names should begin with lower-case. 
    @IBOutlet weak var displayX: UITextField!
    @IBOutlet weak var displayY: UITextField!
    @IBOutlet weak var resultat: UILabel!


    @IBAction func performAddition(_ sender: UIButton) {

        // Use a guard condition to unwrap the variables.
        // Doing this avoids crashes when you force unwrap a nil.
        guard let x = displayX.text, let y = displayY.text else {
            return
        }

        let a = Arithmetic(x: x, y: y)
        let r = a.add()
        resultat.text = "The result of addition is: \(r)"
    }


    @IBAction func performSubtraktion(_ sender: UIButton) {
        guard let x = displayX.text, let y = displayY.text else {
            return
        }

        let a = Arithmetic(x: x, y: y)
        let r = a.subtract()
        resultat.text = "The result of subtraction is: \(r)"
    }
}