Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Peter Fuhrey
2,146 PointsHelp with unresolved identifier issue in struct method.
Can anyone help me with this code? Or maybe a better suggestion to accomplish this task? It's saying use of unresolved identifier but I thought North was declared in my constant? I'm trying to get it to print out what state you're heading towards depending on your direction. (North = New York, East = Carolinas, South = Florida, West = California) import Foundation
struct CompassPoints {
let compassDirections = ["North", "East", "South", "West"]
func stateBound() -> String? {
for direction in compassDirections {
switch direction {
case North:
return "You're heading towards New York"
}
}
}
}
1 Answer

agreatdaytocode
24,757 PointsTry this:
enum CompassPoints {
case North, East, South, West
func stateBound() -> String {
switch self {
case .North: return "New York"
case .East: return "Carolinas"
case .South: return "Florida"
case .West: return "California"
}
}
}
let North = CompassPoints.North
let Northdir = North.stateBound()
println("You're heading towards \(Northdir).")