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

What's wrong with this instance method?

No matter how hard I look, I can't see why this code isn't passing the code challenge. When I put it into an XCode playground, it gives me the result I expect.

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

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

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Derek,

This is a simple spacing issue. You should have equal spacing before and after the return operator:

spacing.swift
// func description() ->String {
func description() -> String {

I don't think this would cause a compile error, but it's a good style habit to get into. I think the code challenges use SwiftLint, which enforces good style. Check out the GitHub repo.

As an aside, sloppy spacing is something that drives me crazy about Gabe Nadel's videos. He is super-inconsistent with his spacing, and maybe it's just my OCD, but it kills me.

Cheers :beers:

-Greg

Many thanks, that fixed it and gave me a good tip too!

Greg Kaleka
Greg Kaleka
39,021 Points

Sure thing! One extra tip: incorrect spacing will cause a compile error for assignment. Type the following into a playground:

let myVar =1
let otherVar= 1
let thirdVar=1
let fourthVar = 1

The first two will throw errors, while the last two will not. I very strongly prefer the last one, and that's how you'll see it done almost always. It's how you're doing it already, so that's good :blush:.