复杂词典在 swift 中阻止了 Xcode 编译操作
Complex Dictionary blocked Xcode compile operation in swift
xCode 7.1 + swift2.1 + iOS 9.0
下面的代码阻止 Xcode 编译操作。
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)")
Playground 是 运行 运行,从来没有弄清楚 anything.So 这是否发生在 iOS project.No 错误中,只是 运行。
您的 data
键有一个复杂的嵌套结构,所以 Swift 的类型推断系统失败了。在我的 Xcode 7.1.1 中,它给出了 "Type is ambiguous without more context" 错误。
向编译器提示数据类型:
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
]
xCode 7.1 + swift2.1 + iOS 9.0
下面的代码阻止 Xcode 编译操作。
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)")
Playground 是 运行 运行,从来没有弄清楚 anything.So 这是否发生在 iOS project.No 错误中,只是 运行。
您的 data
键有一个复杂的嵌套结构,所以 Swift 的类型推断系统失败了。在我的 Xcode 7.1.1 中,它给出了 "Type is ambiguous without more context" 错误。
向编译器提示数据类型:
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
]