2015-11-14 39 views
-2

xCode 7.1 + swift2.1 + iOS 9.0
下面的代碼阻止Xcode編譯操作。複雜的字典封鎖Xcode編譯操作在swift

let dic_1:Dictionary<String,Int> = ["key":200] 
print("dic_1---->\(dic_1)") 

這是否發生過任何人?這是怎麼發生的?


感謝您糾正語法錯誤。

我發現它不是上述代碼的原因。

我起源代碼如下:

let dic_1 = [ 
    "status": 200, 
    "info": "1234", 
    "data":[ 

     "st_id":"st_id", 
     "st_name":"radiant", 
     "address":"dire", 
     "longitude":"122.111", 
     "latitude":"123.000000", 
     "is_favorite":"0", 
     "score":"5", 
     "thumbnail":"www.baidu.com", 
     "comment_count":"45612", 
     "cert_img_url":"www.baidu.com", 
     "has_inspay":"1", 
     "has_car_discount":"1", 
     "has_groupon":"1", 
     "score_environment":"4.5", 
     "score_service":"5.0", 
     "score_oil":"5.0", 
     "type":"98", 
     "city":"SHENZHEN", 
     "show_price_discount":"1", 
     "is_support_invoice":"1", 
     "price":[ 
      [ 
       "oil_name":"95#", 
       "market_price":"6.23", 
       "sell_price":"6.00", 
       "wecar_price":"-100.00" 
      ], 
      [ 
       "oil_name":"95#", 
       "market_price":"6.23", 
       "sell_price":"6.00", 
       "wecar_price":"-100.00" 
      ], 
      [ 
       "oil_name":"95#", 
       "market_price":"6.23", 
       "sell_price":"6.00", 
       "wecar_price":"-100.00" 
      ], 

     ], 

     "promotions": [ 
      "promotion1", 
      "promotion1", 
      "promotion1", 
      "promotion1" 
     ], 
     "gpns":[ 
      [ 
       "gpn_id":"75642", 
       "gpn_name":"gpn_name", 
       "oil_type":"95", 
       "price":"180", 
       "sell_amount":"20000000", 
       "old_price":"200" 
      ] 
     ], 
     "discount_items":[ 

      [ 
       "desc":"It's a descrition.", 
       "disc_type":"1" 
      ] 
     ] 
    ] 
] 

print("dic_1---->\(dic_1)") 

遊樂場運行運行,從來沒有弄清楚anything.So會發生這種情況在iOS中project.No錯誤,只是運行。

+0

你試圖通過自己讓迅速斷定類型? – kabiroberai

+1

也許你應該刪除前導單引號字符 – vadian

+2

什麼是錯誤信息?該代碼在遊樂場中工作正常 –

回答

1

對於data密鑰,您已經有了複雜的嵌套結構,因此Swift的類型推斷系統失敗。在我的Xcode 7.1.1中,它給出了「類型不明確,沒有更多上下文」的錯誤。

給編譯器的提示,數據類型:

let data: [String: Any] = [ 
    "st_id":"st_id", 
    "st_name":"radiant", 
    "address":"dire", 
    "longitude":"122.111", 
    "latitude":"123.000000", 
    "is_favorite":"0", 
    "score":"5", 
    "thumbnail":"www.baidu.com", 
    "comment_count":"45612", 
    "cert_img_url":"www.baidu.com", 
    "has_inspay":"1", 
    "has_car_discount":"1", 
    "has_groupon":"1", 
    "score_environment":"4.5", 
    "score_service":"5.0", 
    "score_oil":"5.0", 
    "type":"98", 
    "city":"SHENZHEN", 
    "show_price_discount":"1", 
    "is_support_invoice":"1", 
    "price":[ 
     [ 
      "oil_name":"95#", 
      "market_price":"6.23", 
      "sell_price":"6.00", 
      "wecar_price":"-100.00" 
     ], 
     [ 
      "oil_name":"95#", 
      "market_price":"6.23", 
      "sell_price":"6.00", 
      "wecar_price":"-100.00" 
     ], 
     [ 
      "oil_name":"95#", 
      "market_price":"6.23", 
      "sell_price":"6.00", 
      "wecar_price":"-100.00" 
     ], 

    ], 

    "promotions": [ 
     "promotion1", 
     "promotion1", 
     "promotion1", 
     "promotion1" 
    ], 
    "gpns":[ 
     [ 
      "gpn_id":"75642", 
      "gpn_name":"gpn_name", 
      "oil_type":"95", 
      "price":"180", 
      "sell_amount":"20000000", 
      "old_price":"200" 
     ] 
    ], 
    "discount_items":[ 

     [ 
      "desc":"It's a descrition.", 
      "disc_type":"1" 
     ] 
    ] 
] 

let dic_1: [String: Any] = [ 
    "status": 200, 
    "info": "1234", 
    "data": data 
] 
+0

這是答案。我的Xcode沒有編譯錯誤。這是我的生成設置的原因嗎?我使用默認設置。我是否需要打開其他警告? – Jules

+0

我也使用了默認的構建設置。我的Xcode版本是7.1.1。你的是啥呢? –

+0

我的Xcode版本也是7.1.1。它沒有抱怨錯誤。 爲了加速編譯,請給編譯器一個關於數據類型的提示。 – Jules