How do I hide a button using Swift5 when an 'if' condition is true?

I am trying to hide a button called "itemOneDelete" when a label ("itemOneLabel") on my View Controller is empty, by using an 'if' loop to change the visibility of the button to "alpha = 0" by using the following code:
Code Block
@IBAction func itemOneDelete(_ sender: UIButton) {
if self.itemOneLabel.text == "" {
itemOneDelete.alpha = 0
}

However I am receiving the following error for the itemOneDelete.alpha = 0 line and I can't seem to fathom why.

Value of type '(UIButton) -> ()' has no member 'alpha'

I have also tried replacing line three with the following syntax, however I received a similar error:

Code Block
itemOneDelete.hidden = true

Value of type '(UIButton) -> ()' has no member 'hidden'

Can anyone explain why I am getting this error and how to resolve it please?
Accepted Answer

a button called "itemOneDelete"

I guess you have two different kinds of itemOneDelete, a button and the method itemOneDelete(_:). And Xcode is assuming itemOneDelete as the method, not the button.

Generally, Xcode can distinguish the two things if you declare them properly.
Do you have the IBOutlet declaration of the button itemOneDelete?
Code Block
@IBOutlet weak var itemOneDelete: UIButton!


Or else, there may be something wrong in the other parts of your code.
Can you show whole code of your view controller?


By the way, your question has nothing to do with the SwiftUI framework. The tag SwiftUI is not appropriate for your question.

what is your IBAction connected to ?
Who is sender ? Is it itemOneDelete ?

If so, just write:

Code Block
@IBAction func itemOneDelete(_ sender: UIButton) {
if self.itemOneLabel.text == "" {
sender.alpha = 0
}


The cause of the error was explained by OOPer.
Hi OOPer, I've managed to resolve this issue by using

Code Block
sender.hidden = true

Thank you for your explanation as to why I was receiving the error. My apologies for using the incorrect tag.
You did it in IBAction as I proposed ?

Don't forget to close the thread.
Yes, I did it in IBAction. My apologies, I have closed my old threads now.
How do I hide a button using Swift5 when an 'if' condition is true?
 
 
Q