値を配列として定義しています。 (配列内の)値は別の関数から取得され、クラスの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
}
BusStopクラス内のbusStopArrayとしてbusStopIdentities.busStopArrayをアクセスします。 –
それでも、busStopIdentities @ Annishの下で同じエラーがスローされます。 –
busStopIdentities.busStopArrayをメソッド内に配置します。内部のinit()メソッドを入れてテストします。 –