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

Rodney Aiglstorfer
Rodney Aiglstorfer
450 Points

Why wont this code compile? It works find in the Playground.

There are no reported errors in Playground when I run the code, I suspect this is a limitation of the website and its need to find an exact match with the code it is looking for. I wish there was some way to skip and move on. It has totally blocked my ability to move forward.

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

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

let postDescription = firstPost.description()

1 Answer

andren
andren
28,558 Points

You are correct, this is an issue of the code checker looking for a specific style of code. The issue is that it expects Post to take the arguments title, author, tag in that exact order. You have the right argument names but the wrong order. If you simply move the title constant above the author and change the instantiation code to match like this:

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: "iOSDevelopment", author: "Apple",
tag: Tag(name:"swift"));

let postDescription = firstPost.description()

Then your code will pass the challenge.

You can technically skip past challenges by using the navigation dots that are found above the workspace, they show you how far you are in a specific section of a course but can also be used to skip back and forth between parts of the section by clicking on them. This won't mark them as complete though so the course will not be marked as finished before you actually complete the challenges.