我有一本字典,我需要將其轉換爲數組,但無法完成實現。在InterfaceController
值從值字典獲取數組
字典...在Event
類值的
var receivedData = Array<Dictionary<String, String>>()
func session(session: WCSession, didReceiveUserInfo userInfo: [String : AnyObject]) {
if let tColorValue = userInfo["TeamColor"] as? String, let matchValue = userInfo["Matchup"] as? String {
receivedData.append(["TeamColor" : tColorValue , "Matchup" : matchValue])
let eventsList = Event.eventsListFromValues(receivedData)
for eventM in eventsList {
NSLog("Event Match: %@", eventM.eventMatch)
}
} else {
print("tColorValue and matchValue are not same as dictionary value")
}
}
過程詞典:
class func eventsListFromValues(values: Array<Dictionary<String, String>>) -> Array<Event> {
var array = Array<Event>()
for eventValues in values {
let event = Event(dataDictionary: eventValues)
array.append(event)
}
return array
}
}
無法弄清楚這部分...使用陣列設置在setupTable
表:
func doTable() {
// ...get array of `match`s for use in table set up
// ...Then set number of Rows
// ...Then iterate thru the array
for var i = 0; i < self.rowTable.numberOfRows; i++ {
var row = self.rowTable.rowControllerAtIndex(i)
// ...setup text label
}
}
編輯:澄清
doTable
將獲得收到的任何match
s並將其顯示在表中。所以我認爲我應該做的是獲得一個match
s的數組,然後使用它們來設置表中的文本標籤。
編輯2:這是我迄今爲止
class InterfaceController: WKInterfaceController, WCSessionDelegate {
class EventSO {
var teamColor:String!
var matchup:String!
init(dataDictionary:[String:String]) {
teamColor = dataDictionary["teamColor"]
matchup = dataDictionary["Matchup"]
}
}
var receivedDataSO = [Event]()
var tColorValueSO = "Red"
var matchValueSO = "someString"
var eventSO = EventSO(dataDictionary: ["teamColor": tColorValueSO, "Matchup": matchValueSO])
故事板:
你想要什麼的'doTable'方法呢? – Adam
我不是100%確定你在這裏做什麼,receivedData是一個字典數組了嗎?你能澄清一下嗎?你能告訴我們你想在doTable中做什麼以及事件是什麼嗎? – Scriptable
@亞當嗨亞當,我添加了上面的編輯嘗試進一步澄清,但基本上'doTable'將設置我的WatchKit表。因此,在'doTable'裏面,我需要獲得一串'match',我可以遍歷它來構建表格並設置標籤的文本。我希望這更有意義!讓我知道如果不是 - – SRMR