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 trialCian Brennan
1,573 PointsWhy is the function accepting a dictionary?
Why is the function accepting a dictionary? The Struct doesn't contain any dictionaries so why is Pasan using one in the initializer?
1 Answer
Andrew Shook
31,709 PointsThe function accepts an dictionary, because it is a factory ( it creates other things). Pasan is trying to show you an example of a common task when programming, while also teaching you about early returning. In most cases, when you work with data it's going to start out as an array or dictionary, like when you receive data from an api call. You want to take this raw data and convert it into model or some other kind of object that is specific to your task. So you take that data and pass it to a factory, then the factory passes back the object you need, or nil if it fails.