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
Roberta Voulon
5,792 PointsWhen do we need to add parentheses() after a protocol name?
In this video Pasan has us write the following line:
var d6 = Dice(sides: 6, generator: LinearCongruentialGenerator())
I'm wondering why we need to write the parentheses() after the protocol LinearCongruentialGenerator, especially as we haven't had to do so in the previous examples, like the one for Blendable:
let ingredients: [Blendable] = [strawberry, chocolateMilk]
1 Answer
Roberta Voulon
5,792 PointsAh cripes, I just figured out that the protocol actuall is RandomNumberGenerator and the class LinearCongruentialGenerator implements it... my bad :)
Stepan Ulyanin
11,318 PointsStepan Ulyanin
11,318 PointsLinearCongruentialGenerator is a class and you need to create an instance of the class, so you use:
LinearCongruentialGenerator()(only if you won't specify any other initializers), the class conforms to protocol, it is not a protocol itself