2016-10-26 2 views
0

値を配列として定義しています。 (配列内の)値は別の関数から取得され、クラスのJSONSerializationによって定義されます。私は値を構造体に渡す必要があります(グローバルにアクセスできるように、私の他のポストhttps://stackoverflow.com/questions/40180767/access-value-of-variables-from-other-classesに関連しています)。しかし、それは通常の辞書として振舞うようには見えない。クラスから構造体にデータを追加する方法は?予期した宣言をスローする

これは、クラスと構造体を含む、特定の迅速なファイルのコード全体です。どんな助けでも感謝しています。

編集:エラー

struct busStopIdentities 
{ 

static var busStopArray : [String : [AnyObject]] = ["busStopCode_as_identifier" : ["busStopData" as AnyObject]] 

} 

class BusStop 
{ 

var busStopCode : String? 
var roadName : String? 
var busStopDescription : String? 
var busStopLatitude : Double? 
var busStopLongitude : Double? 

init(jsonDataDictiony : [String : AnyObject]) 
{ 

    //print(jsonDataDictiony) 

    if let valueArray = jsonDataDictiony["value"] as? [[String : AnyObject]] 
    { 

     for valueDictionary in valueArray 
     { 

      self.busStopCode = valueDictionary["BusStopCode"] as? String 
      self.roadName = valueDictionary["RoadName"] as? String 
      self.busStopDescription = valueDictionary["Description"] as? String 
      self.busStopLatitude = valueDictionary["Latitude"] as? Double 
      self.busStopLongitude = valueDictionary["Longitude"] as? Double 

     } 

    } 

} 

busStopIdentities.busStopArray[busStopCode] = [busStopCode, roadName, busStopDescription, busStopLatitude, busStopLongitude] 
^ expected declaration 

} 
+0

BusStopクラス内のbusStopArrayとしてbusStopIdentities.busStopArrayをアクセスします。 –

+0

それでも、busStopIdentities @ Annishの下で同じエラーがスローされます。 –

+0

busStopIdentities.busStopArrayをメソッド内に配置します。内部のinit()メソッドを入れてテストします。 –

答えて

-1

構造体がオブジェクトではありませんショーがDATETYPEである、あなたは、変数を作成する必要があり、かつ

VARバス= のように、そのDATETYPEに割り当てますbusStopIdentities(busStopArray [busStopCode]:[busStopCode、roadName、busStopDescription、busStopLatitude、busStopLongitude])

私は素早くわからないので、sintaxが間違っている可能性があります。

関連する問題