2017-06-15 7 views
0

Struct型のオブジェクトのプロパティを割り当てる必要があります。 は、ここに私のStruct:別のクラスのオブジェクトのプロパティのプロパティにアクセスする方法とそれを個別に使用するか? (Swift)

class Api { 
var listado = [Destinos]() 

func GetDestinos(){ 
    listado.append(Destinos(idDestino: 1, desDestino: "Asunción")) 
    listado.append(Destinos(idDestino: 2, desDestino: "Miami")) 
    listado.append(Destinos(idDestino: 3, desDestino: "Atenas")) 
    listado.append(Destinos(idDestino: 4, desDestino: "Londres")) 
    listado.append(Destinos(idDestino: 5, desDestino: "Madrid")) 
} 
} 

class DestinoPresenter { 

var ListaDeDestinos = [String]() 
fileprivate var DestinoLista: Api! 

func searchDestinos(_ substring: String) { 

    DestinoLista = Api() 
    DestinoLista.GetDestinos() 

    //string member variable of each listados object 
    for object in DestinoLista.listado { 
     if (object.desDestino?.lowercased().contains(substring.lowercased()))! { 
      ListaDeDestinos.append(object.desDestino!)     
     } 
    } 
    mview.mostarResultados(ArrayResultados: DestinoLista.listado) 
} 
} 

方法:方法mostarResultadoのための今すぐ

func mostarResultados(ArrayResultados: [Destinos]) { 
    autoCompleteDestino = ArrayResultados 
    tableView.reloadData() 
} 

ところである。このように、彼はプロパティにアクセスするとき

public struct Destinos: Data { 
public var idDestino : Int? 
public var desDestino : String? } 

私は2クラスを持っています私はちょうどdesDestinoの特性を印刷する必要があります...私は今まで成功していない様々な方法を試してみてください...助けてください。

+0

お願いします!私はこれのための任意の解決策を見つけることはありません。 – xhinoda

答えて

0

あなたはこれを試しましたか?

func mostarResultados(ArrayResultados: [Destinos]) { 
     autoCompleteDestino = ArrayResultados 
     for item in autoCompleteDestino{ 

     print(item.desDestino) 
     } 
     tableView.reloadData() 
    } 
+0

ええ...しかし、これは私の場合は解決策ではありません。どうもありがとう...私は違う方法で試してみます。 – xhinoda

+0

親切にあなたのソリューションを共有する必要があります、私のために学ぶべきことがあるかもしれません。 –

関連する問題