Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Alexandre Noto
3,594 Pointsaccess UIView subclass properties in the Gesture recognizer handling method (SWIFT)
in Swift, i am adding gesture recognizers to some elements of my own subclass of UIView. In the recognizer handling method, I can access recognizer.view.
How can I cast this as my own UIView subclass, so that I can access its custom properties from within this method?
1 Answer
Stone Preston
42,016 Pointsyou could use something like this inside the handler
let myView: MyViewSubclass = recognizer.view as MyViewSubclass
myView.customProperty = "blah blah blah"
Alexandre Noto
3,594 PointsAlexandre Noto
3,594 PointsThank you very much for your help. I've tested your solution and it worked. Perfect!
Stone Preston
42,016 PointsStone Preston
42,016 Pointsglad I could help :)