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 trialAudu Alfa
2,494 PointsIssue with task 2 of "Swift Recap 1" code challenge in "Build a Simple iPhone App with Swift 2.0"
I think the code challenge processor is broken. Here's a link to the code challenge:
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
func description () -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let firstPost = Post(title: "Expert Business Analysis", author: "Audu", tag: Tag(name: "Genius"))
let postDescription = firstPost.description()
6 Answers
Angel Caro
11,831 PointsI just ran it again and it stopped working but this is the code that worked:
struct Tag {
let name: String
}
let firstTag = Tag(name: "swift")
struct Post {
let title: String
let author: String
let tag: Tag
func description () -> String {
return "\(title) by \(author). Filed under \(tag.name)."
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: firstTag)
let postDescription = firstPost.description()
It works in the playground but not in the challenge
Angel Caro
11,831 PointsYou have to create a tag with the string "swift" and then print the message "iOS Development by Apple. Filed under swift." replace your firstPost with this:
//Tag
let firstTag = Tag(name: "swift")
let firstPost = Post(title: "iOS Development", author: "Apple", tag: firstTag)
Audu Alfa
2,494 PointsReplaced it exactly as you advised and it's still not giving me joy
Angel Caro
11,831 PointsDid you add the firstTag constant above the Post struct? I just ran the code and it passed.
Angel Caro
11,831 PointsNot a problem.
Audu Alfa
2,494 Pointsit worked it worked it worked. Thanks again for your help
Bobby Rath
4,270 PointsThis didn't work for me. Appears to be bugged as it runs in Playground fine.
Angel Caro
11,831 PointsIf it doesn't work you should report it to treehouse sometimes the code challenge environment gets buggy and they will look into it.
Majed Alshammarii
1,174 PointsI can not do it. Please post it as an answer below. I need it
Audu Alfa
2,494 PointsAudu Alfa
2,494 PointsThanks ever so much Angel. The same thing happened to me. It worked in the playground but for some reason doesn't work in the code challenge. I have notified treehouse. Thanks again
Dominik Metzger
4,959 PointsDominik Metzger
4,959 PointsIn your code is a space between the function name and the (). And the . at the end of the String is too much. With fixing the two things it worked for me