Looking for a way to use Swift extensions in a separate file or an alternative solution. Creating an extension only works as long as the extension is written in the same file it is being used.
Here is an example of the ViewController.swift that works.
import UIKit
var TestHelper: String = "Start Value"
extension UIView {
var testValue:String{
set{
TestHelper = newValue
}
get{
return TestHelper
}
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.testValue = "Some Value"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Taking the extension out of this file and placing in a new file results in a crash giving this error:
Program ended with exit code: 9
This error is saying it doesn't exist I think. Creating the extension in each separate file that the extension is need obviously creates issues with invalid redeclaration.
Thanks in advance!