0
The variable image needs to be initialized in your creation or within the class constructor, or you can say that it can be optional as follows:
var image: UIImage?
This way you will have to check that it is not null when using, or you can declare so:
var image: UIImage!
So you guarantee that it will be initialized in use, but if it is not will give error.
Thank you very much for the answer that was exactly the problem, because I have one more question, for example , what is the difference between 'image = Uiimage()' ' for 'image: Uiimage''
– Bruno Bafilli
@Brunobafilli Como Swift is a dynamic language (however strongly typed), when you do
var image: UIImage
would be something likeUIImage image
in another language (object not yet initialized), alreadyvar image = UIImage()
you are instantiating (initiating) an object of the typeUIImage
and he takes care of typing the variable for you.– Luis Henrique
I understood, so it means that when I do image =Uiimage() I start a variable of the type of the same object, if I do not do it I create a variable of the type of the object because it is not yet ready for use until initialization ?
– Bruno Bafilli
That’s right my dear.
– Luis Henrique
Sorry to bother you with so many questions, but why does it work var button: Uibutton button = view.viewWithTag(i) as! Uibutton , and this is not var image: Uiimage image = Uiimage(named: "Circle.png")!
– Bruno Bafilli