0
私は約8-9回繰り返されている関数を持っています。私は冗長性を減らそうとしています。spefic型を取り、配列を返す関数を作成することは可能です送信されるjsonオブジェクトを使用して初期化された型の関数の引数として特定の型だけを渡す
現在の機能
static func initArray(json: JSON)-> [Event]{
var array = [Event]()
json.forEach(){
array.append(Event.init(json: $0.1))
}
return array
}
所望の機能
static func initArray<T> (type: T, json: JSON)-> [T]{
var array = [T]()
//I get stuck here im not too sure how to initlize the type
//Thats why im wondering if it's possible to pass speific types
//to the function
return array
}