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
Danyil Vayser
1,826 PointsCan I create initializer for dictionary in swift ?
I have a variable in class that needs to use dictionary key and return dictionary value. But I can only assign to a variable in class dictinary with a key inside (var month = monthsOfYear[1]). And as soon as I assign monthsOfYear[1] to var month , I cant change it,
I have a enum Gender and i assign it to a var gender in my class easily (var gender = Gender() ) . Can i somehow do the same with dictionary?
1 Answer
Marlon Henry
6,885 PointsIn a class you can create anything you want. I'm trying to understand the exact question. If you create a class like
class ClassName: NSObject{
var nameOfDictionary
override init() {
}
}
then just initial that class to a variable instance in the class that you want to have access to it, you will have everything you need.