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

iOS

Why is there no argument in an instance method of a struct ?

I was doing a challenge and i saw this code :

struct Parser {
     var data: [String : String?]?
     func parse() throws {
         guard let data = data else {
             throw ParserError.emptyDictionary
          }      
          guard let key = data["someKey"] else {
             throw ParserError.invalidKey
             }   
      }
}

Why the function parse doesnt need argument ? for example func parse(dic data: [String : String?]?)

Thanks !

2 Answers

I don't know what video this is but it looks like an outside class is going to be populating the variable data with key value pairs. The function parse is in the same scope so it seems it would be unnecessary to pass a dictionary into the variable 'data' and then also pass the same dictionary into the function.

Ok i see thanks, i've found on the swift doc "An instance method has implicit access to all other instance methods and properties of that type."

Can you link the video?