Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift Complex Data Structures Declaring a Struct

Olivia SHAW
Olivia SHAW
810 Points

My response to the challenge is incorrect. Why? struct User { let name: String let age: Int }

why is this wrong:

struct User { let name: String let age: Int }

objects.swift
// Enter your code below
struct  User {
let name: String
let  age: Int
}

3 Answers

andren
andren
28,503 Points

The issue is that the challenge checker that verifies your code can at times be very picky about how your code looks. In this case it doesn't like the fact that there are two spaces between struct and User. If you remove the extra space like this:

struct User {
let name: String
let age: Int
}

Then your code will be accepted.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,538 Points

Hi Olivia,

While 'technically' not wrong, the spacing and indentation is all off. Though Whitespace doesn't really matter in Swift, there are certain conventions that should be followed. Here you are receiving the Bummer because you have an extra space after the struct key word before the name of the Struct, so the code checker is going to return an error, because that space becomes part of the Struct's name and <space>User is not what the instructions asked for.

It is a good idea to follow the formatting conventions of any language, as this will make it easier for others to read you code, and prevents you from having to redo 100s or 1000s of lines of coding because the person you are coding / building for may not accept improperly formatted code.

Below is your code snippet with proper formatting (and will now pass the challenge).

struct User {
  let name: String
  let age: Int
}

Keep coding! :) :dizzy:

Olivia SHAW
Olivia SHAW
810 Points

Thank You! It did work after I answered on my IPAD. I've been going back and forth between my IPAD and my laptop. Thanks again!