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

Bekzod Rakhmatov
Bekzod Rakhmatov
7,419 Points

What am I doing wrong?

I did as in written on quiz but it says error!

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

3 Answers

Maria Angelica Dadalt
Maria Angelica Dadalt
6,197 Points

I did the challenge using your code and I know now what is "wrong". The code checker on this site is VERY perticular about everything, event the order that you write properties and arguments. So you have to change the order of author and title, so the code looks like this:

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.name)"
    }
}

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

I hope it works now!

Bekzod Rakhmatov
Bekzod Rakhmatov
7,419 Points

This is crazy it worked I did not think about it the order also make sense here ! Thanks a lot!

Maria Angelica Dadalt
Maria Angelica Dadalt
6,197 Points

Change the properties on the Post struct to variables. It worked for me. Also, I think your last constant is misnamed. Shouldn't it be postDescription?

Bekzod Rakhmatov
Bekzod Rakhmatov
7,419 Points

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

I changed but the result is like this "iOSDevelopment by Apple. Filed under Tag(name: "swift")

Maria Angelica Dadalt
Maria Angelica Dadalt
6,197 Points

The interpolation in your method is wrong. You have to use the dot notation to access the name property and the sintax is missing the backslash. It should be like this:

"\(title) by \(author). Filed under \(tag.name)"
Bekzod Rakhmatov
Bekzod Rakhmatov
7,419 Points

I think question itself is wrong because Xcode almost shown the result which is correct

struct Tag {
    let name: String
}
struct Post {
    var author: String
    var title: String
    var tag: Tag
    func description() -> String
    {
        return "\(title) by \(author). Filed under \(tag.name)"
    }
}
let firstPost = Post(
    author: "Apple",
    title: "iOSDevelopment",
    tag: Tag(name: "swift")
)
let postDescription = firstPost.description()