Vorrei creare una funzione di supporto generica che elabori alcune elaborazioni. Uno dei suoi input sarà una funzione che restituisce una matrice di qualcosa.L'argomento per il parametro generico "T" non è stato dedotto
Non riesco a capire come farlo. Continuo a ricevere un errore di compilazione. Ho trovato il posto
argument for generic parameter could not be inferred
e provato ad aggiungere ...as [String]
o ... as [Int]
, ecc, ma senza fortuna.
func helperThatDoesSomeGenericProcessing<T>(displayedStrings:() -> [T]) -> [String]! {
let listOfSomething: [T] = displayedStrings()
// do something with listOfSomething
return ["some", "resulting", "string", "from", "the", "input"]
}
func concreteFunction1() -> [AnyObject]! {
var s: [String] = helperThatDoesSomeGenericProcessing { // ERROR: Argument for generic parameter 'T' could not be inferred.
var str = ["One", "Two", "Three"]
} // tried 'as [String]' here
// do something with s
return s
}
func concreteFunction2() -> [AnyObject]! {
var s: [Int] = helperThatDoesSomeGenericProcessing { // ERROR: Argument for generic parameter 'T' could not be inferred.
var i = [1, 2, 3]
} // tried 'as [Int]' here
// do something with s
return s
}
Che cosa stai cercando di fare esattamente? Questo è piuttosto confuso senza ulteriori dettagli su che tipo di elaborazione si sta tentando di fare ... perché sembra un po 'come un problema XY forse. – nhgrif