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
Hamza Ansari
34 PointsCan I link a button to a function within a class?
I'm working on an app that involves users taking polls then viewing the results for those polls after they submit their vote from multiple choices. Here's the class I've made and the function within it, which is supposed to add a vote to a specific option:
class Counter {
var voteCount: Int = 0
func incrementBy(amount: Int, numberOfTimes times: Int) {
voteCount += amount * times
}
And here's the IBAction I have so far, for what it's worth:
@IBAction func addVote(sender: AnyObject) {
}
I'm just not sure how to bring the function incrementBy into the IBAction function addVote. Can anyone help me with this? Also, do I need to change my code in any way so that the vote count will increase by 1 every time someone selects their choice? I just want to make sure I have it right.