如何将类中的数据附加到结构中?抛出预期的声明

时间:2016-10-26 12:32:39

标签: arrays dictionary struct swift3

我正在定义一个字典,其值为数组。值(在数组内)从另一个函数获得,并通过类中的JSONSerialization定义。我需要将值传递给结构(因此可以全局访问,与我的其他帖子https://stackoverflow.com/questions/40180767/access-value-of-variables-from-other-classes相关)。但是,它似乎不像普通字典那样行事。

这是特定swift文件的整段代码,包括类和结构。感谢任何帮助。

编辑:显示错误的位置

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

}

1 个答案:

答案 0 :(得分:-1)

结构体不是对象是日期类型,你必须创建一个变量,然后分配给那个日期类型,比如

var busS =     busStopIdentities(busStopArray [busStopCode]:[busStopCode,roadName,busStopDescription,busStopLatitude,busStopLongitude])

我不太清楚,所以sintax可能是错的。