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

Editor does not accept my answer?

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

5 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

I just copy-pasted your code and it worked. I would just refresh the page and try again - make sure you copy your code first :)

Hey Greg,

Thanks for your help.

It works for the first test. But for the next step, it warns me that there is no method named description that returns String type.

It looks fine to me but the Editor cries.

Greg Kaleka
Greg Kaleka
39,021 Points

Hm ok I see that now. Pasan Premaratne - this looks like a bug to me. Have a look?

I've filed a bug report with Treehouse support.

Pasan Premaratne
Pasan Premaratne
Treehouse Teacher

Try tag.name in your interpolated string and see if that resolves it. Tag itself cannot be interpolated into a string because it is a custom type. Your code returns this:

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

Why the error message you are getting is so cryptic, that I will check.

Hey Greg,

Videos do not play anymore. Fullstory.com is over quota. Can you pass it to your support team. Below is Chrome console errors when a TTH video page is loaded:

Failed to load resource: the server responded with a status of 503 (OK) frameworks-and-uikit:1 XMLHttpRequest cannot load https://www.fullstory.com/rec/page. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://teamtreehouse.com' is therefore not allowed access. The response had HTTP status code 503.

Greg Kaleka
Greg Kaleka
39,021 Points

Hey Joseph,

I actually don't work for Treehouse - can you send an email to them? help@teamtreehouse.com

struct Tag {
    let name: String
}

struct Post{
let title: String
let author: String
let tag:Tag
func description()->String {
 return "iOSDevelopment by Apple. Filed under swift"
}
}

let firstPost=Post(title:"iOSDevelopment",author:"Apple",tag:Tag(name:"swift"))
let postDescription=firstPost.description()

tag.name did not help. Even providing the whole string litereal does not help.

Warning says:

Bummer. Make sure you are declaring an instance method named description that returns a String.

Although the method returns a String.

Pasan Premaratne
Pasan Premaratne
Treehouse Teacher

Is the code you're copying exactly what you have in your editor? Whitespace is important in programming. Swift has syntactically enforced rules as well as stylistically enforced ones. (These rules are mentioned in both the courses under naming conventions, as well as in the official Swift book). We test for both because lack of stylistic rules would be noticed in a job interview.

The correct (community adopted and enforced) way to declare a function signature is as follows:

func description() -> String {}

as opposed to what you have:

func description()->String {}

This may be why you're getting it wrong because we're looking for a particular function signature. I'll make the error message less cryptic and point towards this if it is actually the case.

This rule also applies to lines like this

let postDescription=firstPost.description()

There needs to be a space on either side of the equals sign.

Different languages enforce convention differently. With Swift, Xcode won't warn you, but there's a style enforcer you can install as an Xcode plugin (it is a bit tricky though).

This seems trivial but writing readable code is an important tenet of software development and often a good indicator of experience level if job hunting is your goal.

Hey Pasan,

Thank you very much for your help. Indeed, fixing those space issues solved the problem.

Cheers