If I declare an empty image:
var myImage: UIImage?
and then give it a value:
myImage = UIImage(named: "drawing.png")
how can I later remove that value, returning it to its original empty state?
No, weak and optional are not the same, but there is some interplay between the two. Optional just means that a variable can be nil , either by assigning nil yourself, or becoming nil through some other means. The weak keyword has to do with memory management.
If my assumption is incorrect, then one quick hack you can quickly do to get rid of the "Optional" in the text is to change your strings to force unwrap item , like so: theYears. text = "\(item!. experience)" .
Forced Unwrapping If you defined a variable as optional, then to get the value from this variable, you will have to unwrap it. This just means putting an exclamation mark at the end of the variable. Optional("Hello, Swift 4!")
var myImage: UIImage?
Is basically short hand for making a UIImage
point to nil
automatically.
So to reset it back to the original value say:
myImage = nil
Set its value back to nil like this
myImage = nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With