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 Swift 2.0 Protocols Swift 2.0 Protocols Declaring a Protocol

Jose Patarroyo
Jose Patarroyo
2,953 Points

challenge 1 Protocols doesn't work

why isnΒ΄'t it working. The challenge was: Declare a protocol named UserType. The protocol defines two requirements: a gettable property named name of type String, and a gettable/settable property named age of type Int Hint: To declare a property as gettable, add { get } after the type. For settable - { set } and combine both to get a gettable and settable property.

protocols.swift
protocol UserType {
var name: String {get}
var age: Int {get set}
}
Jose Patarroyo
Jose Patarroyo
2,953 Points

It needs to have a space before and after "get" and "set"

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Jose is correct. The code should look like this with spaces and all.

protocol UserType {
  var name: String { get }
  var age: Int { get set }
}
Li Lin
Li Lin
Courses Plus Student 2,654 Points

Is it normal in XCode, or just special case here to add the spaces?

Jose Patarroyo
Jose Patarroyo
2,953 Points

I believe it's just in here, I tried the code in Xcode without spaces and it worked fine.

I typed this into the challenge and it says "Bummer!" I'm going to try again, but I don't see the problem.

protocol UserType { var name: String { get } var age: Int { get set }

}

Dalisson Figueiredo
Dalisson Figueiredo
7,731 Points

The problem is with treehouse only, don't worry, just add the spaces between get and the brackets like { get } and { get set } and it will work fine, in xcode it works without the spaces.