I am new to Swift / iOS, so please bear with me:
I am trying to access a function in one class from another class and update the name of UIImage.
In my viewcontroller class I have
class Documents: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var UpdateImage: UIImageView
override func viewDidLoad() {
super.viewDidLoad()
UpdateImage()
}
func UpdateImage() {
UpdateImage.image = UIImage(named: "NewImage")
}
}
Everything works, the image is updated to "NewImage"
Question: I can access the UpdateImage function from another class, but why does it generate an error when I try to change the image in the Documents class?
class GetChanges {
var success = { operation:AFHTTPRequestOperation!, response:AnyObject!) -> Void in
var MakeChange = Documents()
MakeChange.UpdateImage()
}
}
This generates an error in "UpdateImage.image = UIImage (named:" NewImage ") in the Documents class; "Fatal error: Zero unexpectedly found while expanding optional value"
source
share