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 Generics in Swift Generic Types Creating a Generic Type

Aananya Vyas
Aananya Vyas
20,157 Points

it shows this in the preview what am i doing wrong??

swift_lint.swift:8:27: error: expected '{' to start getter definition var count : Int {get} ^ my code:

struct Queue<Element> {

    var array: [Element] = []


    var isEmpty: Bool {
        if array.count == 0 {
            return true
        } else {
            return false
        }
    }

    }
generics.swift
struct Queue<Element> {

    var array: [Element] = []
     var count : Int  {get}


    var isEmpty: Bool {
        if array.count == 0 {
            return true
        } else {
            return false
        }
    }

    }

1 Answer

Mikis Woodwinter
Mikis Woodwinter
44,940 Points

Hi Aananya,

It looks like you copy-and-pasted a protocol declaration inside of your struct. Remove the {get} after your count declaration and you should be fine :)

Aananya Vyas
Aananya Vyas
20,157 Points
struct Queue<Element> {

    var array: [Element] = []
     var count : Int  


    var isEmpty: Bool {
        if array.count == 0 {
            return true
        } else {
            return false
        }
    }

    }

it works in xcode.. not here..have tried it before .

Mikis Woodwinter
Mikis Woodwinter
44,940 Points

The Challenge is asking you to make count a computed-property... like you did for isEmpty. Let me know if that helps. Also, for isEmpty, you don't have to manually check the array's count— you can just return array.isEmpty.