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 trialJeff McDivitt
23,970 PointsGenerics Swift 3 - Task 5 of 5
Cannot get the last part of this challenge to pass
struct Queue<Element> {
//Task 1
var array: [Element] = []
//Task 2
var isEmpty: Bool {
if array.count == 0 {
return true
} else {
return false
}
}
var count: Int {
return array.count
}
public mutating func enqueue(_ element: Element){
array.append(element)
}
public mutating func dequeue() -> Element? {
guard array.isEmpty, let element = array.first else { return nil }
return element
}
}
1 Answer
Jeff McDivitt
23,970 PointsThanks Robert I figured it out with the below
public mutating func dequeue() -> Element? {
guard array.isEmpty, let element = array.first else { return nil }
array.remove(at: 0)
return element
}
Robert Berry
iOS Development with Swift Techdegree Student 10,893 PointsRobert Berry
iOS Development with Swift Techdegree Student 10,893 PointsI struggled with this last challenge as well. Here is a solution I just found in the forums that worked.