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

connor hoare
connor hoare
7,933 Points

I believe I have the correct code here can somebody tell me why this is not passing the challenge?

Recapping the object oriented programming

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: "iOS Development", author: "Apple", tag: Tag(name: "Swift"))
let postDescription = firstPost.description

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

First off, it looks like you forgot to call the .description method. Instead, you are assigning the method itself to the postDescription constant, not the result of the method.

Even when you fix that, you still have a bug. If I run the code, I get this result (I changed the casing and punctuation on you strings by the way):

iOSDevelopment by Apple. Filed under Tag(name: \"swift\")

Hmm, looks like the tag is being displayed incorrectly. I'll leave fixing that up to you for now. Let me know if you figure it out!

Cheers!

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

Couple of things:

You need to call the description method on your firstPost instance by doing this:

let postDescription = firstPost.description()

When you leave the () off the end of your method you are assigning that function to the variable instead of assigning the result of that function to the variable.

Second you need to use string interpolation per the instructions, the above answer given will compile but its not doing what was asked. You need to use the Tag property .name to show the string value.

func description() -> String { 
return "\(title) by \(author). Filed under \(tag.name)"
} 
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: "iOS Development", author: "Apple", tag: Tag(name: "Swift"))
let postDescription = firstPost.description()