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 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,558 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,858 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!