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
Colin Senfelds
1,427 PointsCompiler problem? Getting started with iOS development recap part 2. What is going on?
Hi,
I am fairly certain I haven't done anything wrong, especially considering the code shows no compile errors when I check. However, the compiler for the code challenge "swift recap part 2" doesn't seem to work properly. Unless of course the mistake is mine.
I imagine it may have something to do with the fact that whenever I add the period "." to the return string in the "description()" instance method, followed by the word "Filed", both instantly highlight themselves as purple. Why? I couldn't tell you. Even if I separate the strings and add them together for the "return" statement, have no luck.
I either get one of two messages after clicking "check work" with no consistency to which message is shown. One will "remind" me to use string interpolation, which is clearly not the issue. The other will simply tell me my code could not be compiled. And if it is just my mistake, I'd be happy to know.
Please help, thanks!
Colin
ps. I'm not able to upload the screen shots using my iPad right now, it's just not an option presented. Also the wifi card on my computer is shot so I'm stuck with the iPad for code challenges and such for now.
Here's the code copy and pasted:
struct Tag {
let name: String
}
struct Post {
var title: String
var author: String
var tag: Tag
init(title: String, author: String, tag: String) {
self.title = title
self.author = author
self.tag = Tag(name: tag)
}
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let firstPost = Post(title: "Universe", author: "cs", tag: "Astrophysics")
let postDescription = firstPost.description()
1 Answer
Steven Deutsch
21,046 PointsHey Colin Senfelds,
The problem is with the string you are returning from your instance method. You need to be interpolating tag's name property. You don't want to interpolate the instance of tag itself.
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
Good Luck!
Colin Senfelds
1,427 PointsColin Senfelds
1,427 PointsHey Steven,
Thanks for catching that typo. I've tried so many little variations to get past this code challenge haha. When I've written exactly what you wrote in Xcode, everything works perfectly. The problem is that, in the code challenge, with that typo fixed, I still get a bummer message stating the code could not be compiled, and when I hit preview, no errors are displayed at all, just a blank screen as if everything works fine (as it seems it should, confirmed by your input and by Xcode).
Interestingly I did the code challenge directly after this one, and passed it just fine, which involved calling and changing properties of a class from a subclass of a different class using switch. (A little bit different than what's shown here, but includes that same idea I suppose).
Anyway, thanks so much for responding!
Colin