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

can not pass in the value of tag

struct Tag { var name: String = "" }

struct Post {

var title: String = ""
var author: String = ""
var tag = Tag()

init(title: String, author: String, tag name: String) {
    self.title = title
    self.author = author
    self.tag = Tag()
}
func description() -> String {
    let desc = "\(title) by \(author). Filed under \(tag.name)"
    return desc
}

}

var firstPost = Post(title: "iOS Development", author: "Apple", tag: "swift")

let postDescription = firstPost.description()

print(postDescription)

structs.swift
struct Tag {
    let name: String = "swift"
}

struct Post {
    var title: String = ""
    var author: String = ""
    var tag = Tag()
    init(title: String, author: String) {
        self.title = title
        self.author = author
        self.tag = Tag()
    }
    func description() -> String {
        let desc = "\(title) by \(author). Filed under \(tag.name)"
        return desc
    }

}

let firstPost = Post(title: "iOS Development", author: "Apple")

let postDescription = firstPost.description()

1 Answer

Jeff McDivitt
Jeff McDivitt
23,970 Points

There are a few errors with your code

  1. Do not change the code that was given to you for the task
  2. You do not need extra empty Strings and tags after declaring your variables
  3. Not sure why you have the parentheses after tag, it is not a function or computed property; therefore, it cannot be called.
  4. You do not need initialization, the task does not ask for this anywhere
  5. In your description method you just need to return the description all in one line, you do not need the extra variable desc
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: "The Task", author: "Jeff", tag: Tag(name: "One"))
let postDescription = firstPost.description()