user4184036
user4184036

Reputation:

Why is my sender.tag coming back as 0 in SWIFT

I have given a UIButton a tag of 1 inside the interface builder attributes section.

I then want to access the tag value of that button once it is pressed, so far I have done this but it is coming back as 0.

   @IBAction func attractiveMinus(sender: AnyObject) {

        println(sender.tag) //sender.tag comes back as zero.


    }

I am not sure if this is the correct way of finding out the tag of a button can somebody please say where i'm going wrong?

thanks

Upvotes: 1

Views: 1499

Answers (1)

Dave Wood
Dave Wood

Reputation: 13333

That should work, so I'd double check that you've updated the tag of the right button. Make sure that the updated IB files are being included in the build by wiping your derived data. Sometimes when you make a really small change like that, Xcode will use the previous version of the Storyboard/Xib that it has cached.

Also, since you know the sender is going to be a button, you can use UIButton in place of AnyObject to get the most out of Swift's type safety.

Upvotes: 1

Related Questions