2016-10-11 115 views
0
team: [ 
    [ 
     { 
      type: "profile", 
      assists: 8, 
     }, 
     { 
      type: "profile", 
      assists: 9, 
     }, 
    ], 
    [ 
     { 
      type: "profile", 
      assists: 8, 
     }, 
     { 
      type: "profile", 
      assists: 9, 
     }, 
    ] 
] 

這是我的數據,我該如何聲明一個變量?swift聲明和數組包含字典

var info = Array<Dictionary<String, String>()> 
var info = Array<Dictionary<String, Int>()> 

都是不正常

,我想編輯的變量添加一個詞典。 我該如何申報?

回答

2

您可以使用下面的語法:

var info = [[[String: AnyObject]]]() 

更重要的是,你可以使用一個struct

struct TeamMember { 
    var type: String 
    var assists: Int 
} 

var test: [[TeamMember]] = [ 
    [ 
     TeamMember(type: "x", assists: 0), 
     TeamMember(type: "x", assists: 0) 
    ], 
    [ 
     TeamMember(type: "x", assists: 0), 
     TeamMember(type: "x", assists: 0) 
    ] 
] 
+0

感謝實際上 – Scorpio

+0

先謝謝了。 – Scorpio

+0

謝謝。 其實,我的數據是一樣 { 類型: 「個人資料」, \t助攻:8, \t名稱: 「文本」 }, 有很多財產 也許 \t VAR信息= [[[字符串: AnyObject]]]() 更好 – Scorpio

0

我猜你的類型如下:[[[String:AnyObject]]],一個字典數組,其中包含字符串鍵和未定義的對象。