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 Build a Simple iPhone App with Swift Getting Started with iOS Development Swift Recap Part 1

Joel holsinger
Joel holsinger
2,345 Points

Unsure why I am receiving this error.

Bummer! Make sure the implementation of description matches the directions. Hint: Use string interpolation!

I keep receiving this error when trying to complete a code challenge. I can't seem to find any errors with my string interpolation and can't figure out how to debug. Any help would be appreciated.

structs.swift
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)"
}
}
let firstPost = Post(title: "harry potter", author: "tolkien", tag: Tag(name:"Swift"))
let postDescription = firstPost.description()

1 Answer

Jonathan Ruiz
Jonathan Ruiz
2,998 Points

Hey Joel ! you are very very close you got the right idea there is just one thing your missing. When you write out an interpolated string for the last stored property tag it is of type Tag. This means when its assigned to a custom type like a class or a struct you must be specific to the stored property you want. In this example its easy because you have one stored property in the Tag struct. That stored property is name and its of type string, so in your string interpolation you access that stored property with dot notation.

return "\(title) by \(author). Filed under \(tag.name)"

// adding \(tag.name) specifies that you want to access the string we assigned to that stored property. 

I also recommend putting this in an Xcode playground as is on the side bar you can see what the string interpolation prints before and after you use dot notation to get what the instructions wanted. Visual examples like that have helped me the most when learning.

Hope this helps !