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 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

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 .

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.