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 2.0 Getting Started with iOS Development Swift Recap Part 1

Michael Murray
Michael Murray
6,037 Points

Getting compile error. Gives the hint: "Use string interpolation". Can someone look at what I have in my code?

My code: 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: "Heat", author: "MICHAEL MANN", tag: Tag(name: "Action")) let postDescription = firstPost.description()

structs.swift
struct Tag {
    let name: String
}

I'm getting the same error... And I did same as you... The only difference I put self.title, self.author and self.tag.name inside the string interpolation

Michael Murray
Michael Murray
6,037 Points

Stefano Mainarde, I tried what you recommended - put self.title, self.author and self.tag.name inside the string interpolation and it worked. Not 100% clear why but I am going to explore further why it needed the self. leaders.

3 Answers

Digvijay Jaiswal
Digvijay Jaiswal
5,565 Points

Stefano Mainardi and Michael Murray, guys try the code below...

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)") //tag.name is for accessing the name

    }

}


let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "Swift"))

let postDescription = firstPost.description()

Thank you. Guys when I got the error I was using the treehouse App on my iPad... So I tried to write the code using the website and it worked. Maybe there's a problem with string interpolation in the app. I noticed that in the sentence "..Apple. Filed under swift" , the word "Filed" changed color from orange to purple, so I think that's the problem.

Digvijay Jaiswal
Digvijay Jaiswal
5,565 Points

Stefano Mainardi can you mark the answer as the right answer. It will be easier for others to find.