xcode 对成员“计数”的不明确引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34066079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:16:44  来源:igfitidea点击:

Ambiguous reference to member 'count'

iosarraysxcodeswiftswift2

提问by Rahul Mathur

Getting the following error when i migrated my current Xcode (v 7.0.1) project to Xcode 7.1.1

当我将当前的 Xcode (v 7.0.1) 项目迁移到 Xcode 7.1.1 时出现以下错误

  • Ambiguous reference to member 'count'
  • Cannot subscript a value of type 'Array'
  • 对成员“计数”的不明确引用
  • 不能为“数组”类型的值添加下标

Any idea how to resolve above errors?

知道如何解决上述错误吗?

My code is as follows

我的代码如下

  var arrOfRewardDetail : Array = [Dictionary<String, String>]()
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ->  Int {
    return arrOfRewardDetail.count //Ambiguous reference to member 'count'
}

 if self.arrOfRewardDetail[indexPath.row]["KEY"] == "Promotion By : "{} // Cannot subscript a value of type 'Array'

UpdateNow getting the following errors

立即更新出现以下错误

  • Ambiguous reference to member 'indexOf' let indexOfEnum : Int = self.arrPromitionDetailEnum.indexOf(dictRewardInfo["r_promotion_detail_type"]!)!
  • Also this one let indexOfEnum : Int = self.arrPromitionDetailEnum.indexOf(dictInfo["r_promotion_detail_type"]!)! // Cannot subscript a value of type 'Array'
  • 对成员“indexOf”的不明确引用 let indexOfEnum : Int = self.arrPromitionDetailEnum.indexOf(dictRewardInfo["r_promotion_detail_type"]!)!
  • 还有这个 let indexOfEnum : Int = self.arrPromitionDetailEnum.indexOf(dictInfo["r_promotion_detail_type"]!)! // Cannot subscript a value of type 'Array'

回答by Eric Aya

Just remove the : Arraypart:

只需删除: Array部分:

var arrOfRewardDetail = [Dictionary<String, String>]()

The compiler will infer the right type, which is [Dictionary<String, String>], not just Array.

编译器将推断正确的类型,即[Dictionary<String, String>],而不仅仅是Array.