Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access UIButton via tag in Swift

Objective-C

UIButton *tmpButton = (UIButton *)[self.view viewWithTag:tmpTag];

How to make this in Swift ?

like image 976
WebOrCode Avatar asked Aug 23 '14 10:08

WebOrCode


1 Answers

In Swift, this would look like this:

var tmpButton = self.view.viewWithTag(tmpTag) as? UIButton

It is more or less a direct translation, except the cast is at the other end of the expression.

like image 153
Sergey Kalinichenko Avatar answered Nov 09 '22 20:11

Sergey Kalinichenko