Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: error: use of undeclared type 'T'

Swift 3.0 and getting this error, unsure why:

Code:

func rest(_ list: ArraySlice<T>) -> ArraySlice<T> {
    return list.dropFirst()
}

Error:

error: repl.swift:1:48: error: use of undeclared type 'T'
func rest(_ list: ArraySlice<T>) -> ArraySlice<T> {
                                               ^
like image 836
at. Avatar asked Oct 13 '16 21:10

at.


1 Answers

You need to specify the generic parameter of ArraySlice, just using as ArraySlice<T> does not declare T:

func rest<T>(_ list: ArraySlice<T>) -> ArraySlice<T> {
    return list.dropFirst()
}

Or:

class MyClass<T> {
    func rest(_ list: ArraySlice<T>) -> ArraySlice<T> {
        return list.dropFirst()
    }
}
like image 189
OOPer Avatar answered Sep 28 '22 15:09

OOPer