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

Paulina Dao
Paulina Dao
2,148 Points

Why am I getting a string interpolation error?

Not quite sure why I'm getting a use string interpolation error. Code compiles just fine without any errors but it won't submit.

structs.swift
struct Tag {
    let name: String
}

struct Post {
    let title: String
    let author: String
    let tag: Tag

    func description() -> String {
      let description = "\(title) by \(author). Filed under \(tag)"
      return description
    }
}

let firstPost = Post(title: "Title", author: "Author", tag: Tag(name: "tag"))

let postDescription = firstPost.description()

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Paulina Dao,

You're just making the most common mistake people have when taking this challenge. For your description, you want to be using String Interpolation on tag's name property. You are currently using interpolation on the tag instance itself. This is not the value we're looking for. You can access the name property of tag by using dot syntax.

I also reformatted your description method to return the string directly instead of storing it in a variable to return afterwards. There's no need to bind the value to a variable/constant here since we will never use the value prior to returning it.

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: "Title", author: "Author", tag: Tag(name: "tag"))

let postDescription = firstPost.description()

Good Luck