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 Functions, Parameters and Constraints Generic Functions

John Wilcox
John Wilcox
4,233 Points

Error "Make sure your function name and arguments match those specified in the directions"

Hi, me again. My function name, arguments and return type do appear to match the directions. Am I just not seeing something?

generics.swift
func duplicate<T>(_ item: T, _ numberOfTimes: Int) -> [T] {

var arrayToReturn = [T]()

  for _ in 1...numberOfItems {
    arrayToReturn.append(item)
  }

return arrayToReturn

}

1 Answer

Dhanish Gajjar
Dhanish Gajjar
20,185 Points

In your function you have omitted the external names. Remove the _ and keep the names as

func duplicate<T>(item: T, numberOfTimes: Int) -> [T] {}

There are no mistakes in the functions, other than that. :)

John Wilcox
John Wilcox
4,233 Points

I thought I had tried it that way also - with no _'s - and got the same "specified in directions" error. I must have left something out or miskeyed. Thank you for your help. I swear I'm syntax dyslexic.