【发布时间】:2015-10-02 02:29:37
【问题描述】:
我即将在我的 Swift 2.0 应用中实现 Realm 模型。但是,一旦我 pod 安装 Realm。我的应用程序的 AnyObject 下标将导致编译错误
不能用“String”类型的索引为“AnyObject”类型的值下标
不能用“String”类型的索引为“RLMProperty”类型的值下标
从“RLMProperty”到“AnyObject”的条件转换总是成功
但事情是出口不应该是一个 RLMProperty 放在首位
以下是我的代码
var campaigns = [AnyObject]()
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let campaignCell = tableView.dequeueReusableCellWithIdentifier("campaignCell", forIndexPath: indexPath) as! CampaignTableViewCell
let outlet: AnyObject = (self.campaigns[indexPath.section]["surveys"]!![indexPath.row])["outlet"]!!
// Configure the cell...
campaignCell.outletID.text = outlet["code"] as? String
campaignCell.outletNameLabel.text = outlet["name"] as? String
//campaignCell.outletAddressLabel.text = outlet["outlet"]!!["address"] as? String
campaignCell.outletStatusLabel.text = (self.campaigns[indexPath.section]["surveys"]!![indexPath.row])["progress"]!!["name"] as? String
campaignCell.outletStatusLabel.textColor = UIColor.colorWithHexString(((self.campaigns[indexPath.section]["surveys"]!![indexPath.row])["progress"]!!["color"] as? String)!)
return campaignCell
}
【问题讨论】:
-
这个问题在 Realm-Cocoa 存储库中也以Github issue 的形式提出。
-
您能否提供有关此问题的更多信息?哪些行与这些错误相关联?
-
我在项目中也看到了同样的错误。当我在项目的一个文件中导入 RealmSwift 时,它就出现了。除了 import 语句之外,它没有对 Realm 的任何引用。
-
@Happiehappie:你能解决我在 GitHub 问题上提出的问题吗?
-
@angelo:另一个问题是,除了 Realm 之外,您还导入了哪些其他 3rd 方框架?