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

Royce Pollard
Royce Pollard
24,267 Points

I am getting an error about following quiz directions using string interpolation. However, I think I'm using correctly.

Not sure if it is bug in the quiz but from my code I do not understand what exactly the quiz wants. This is what it entails.

///////////

We learned about instance methods before. For this task, add an instance method to Post.

Name the method description. It takes no parameters and returns a string that describes the post instance. For example given a title: "iOS Development", author: "Apple" and a tag named "swift", the description would read as follows"

"iOS Development by Apple. Filed under swift"

Once you have an instance method, call it on the firstPost instance and assign the result to a constant named postDescription.

/////////

I have even changed the values of firstPost to imitate the those of the example and I still do not pass. Any suggestions?

structs.swift
struct Tag {
    let name: String
}

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


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

}

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

  let postDescription = firstPost.description()

2 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Royce Pollard,

You're just interpolating the wrong thing inside your description method. You need to be accessing the name property of the tag instance. You can do this using dot syntax.

struct Tag {
    let name: String
}

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


  func description() -> String {
    // We want to access the Tag instance's name property
    // We do this by tag.name
    return "\(title) by \(author). Filed under \(tag.name)"
  }

}

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

  let postDescription = firstPost.description()

Good Luck

Royce Pollard
Royce Pollard
24,267 Points

Thanks Steven Deutsch,

Do you mind just quickly elaborating on why the property in the struct Post does not work and I have to use dot syntax?

Steven Deutsch
Steven Deutsch
21,046 Points

Yes, my apologies. I was trying to do it quickly before dinner.

When you refer to tag, you are talking about the property inside of the Post struct that is of type Tag. This property is initialized with a specific instance of Tag. What you want to return in the string is not that instance of tag, but that instances name property. We use dot syntax to drill down into the Tag struct's name property from the Post's tag property.

Does this help?

Basically tag refers to the instance, where as tag.name refers to the name property of that instance.

Royce Pollard
Royce Pollard
24,267 Points

Steven Deutsch,

Yup, Makes sense. I get it now. I don't know what I was thinking. I need to focus up. Thanks again. Enjoy your dinner bro.