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 trialVladimir Ulyanov
14,023 PointsUnsure as to how the second way of specifying type works.
At 8:00 Pasan shows us a new way to specify the type that the results constant will accept.
I understand how the below works:
var results: [Point] = []
It looks like the result is the same, but I'm not exactly sure why the code below does the same thing:
var results = [Point]()
Can anyone clarify for me, or point me to the right place in the Swift documentation?
1 Answer
Vladimir Ulyanov
14,023 PointsWhilst doing something unrelated I was reviewing the documentation for String and came upon a new way to create an empty string:
let emptyString = String()
I guess this is just a standard way to create an empty type of any kind!
I was confused at first but I see how it works now I've seen examples of different types using this syntax.
Jialong Zhang
9,821 PointsJialong Zhang
9,821 PointsI think just two different ways to write the code. Similar to counter += 1 or counter = counter + 1