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