无法转换类型'Swift._ContiguousArrayStorage崩溃的值

时间:2017-08-12 08:06:32

标签: ios swift3

我正在尝试将数据从模型类设置为表视图。但它崩溃了并且给了我这个错误“无法将'Swift._ContiguousArrayStorage<AppName.Events>' (0x7feb2444e0b8)类型的值转换为'AppName.Events' (0x105bcd0d0)”。这是我的代码

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


    if tableView.tag == 201
    {
        // On this line it's crashing
        let item = selectedDateEventArr.object(at: indexPath.row) as! Events

        if item.eventType == "LEAVE" || item.eventType == "BIRTHDAY"{
            let cell = tableView.dequeueReusableCell(withIdentifier: "cellBdayId", for: indexPath) as! MainPageBDayTableViewCell

            cell.nameLbl.text = item.title
            cell.eventtypeLbl.text = item.description
           //                cell.imageView?.image = 
            return cell
        }
        else
        {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! MainPageCalTableViewCell
            cell.backgroundColor = UIColor.red
            cell.statusBtn.addTarget(self, action: #selector(statusBtnClicked(_:)), for: UIControlEvents.touchUpInside)
            return cell
        }

    }
 }

selectedDateEventArr是mutableArray,我在匹配当前日期后添加了Events类的对象。

   var selectedDateEventArr = NSMutableArray()
   let dt = Date()
    var dt1 = ConstantFile.dateToStringTemp(date: dt)
    for item in eventsArr {
        if (item.date == dt1){
            selectedDateEventArr.add(item.events!)
        }
    }         

模型类

 class Events: Mappable {
   var date: String?
   var eventId: Int?
   var description: String?
   var eventStatus: String?
   var eventType: String?
   var imageUrl: String?
   var isOwn: Bool?
   var title: String?

   required init?(map: Map){

   }

func mapping(map: Map) {
    date <- map["date"]
    eventId <- map["eventId"]
    description <- map["description"]
    eventStatus <- map["eventStatus"]
    eventType <- map["eventType"]
    imageUrl <- map["imageUrl"]
    isOwn <- map["isOwn"]
    title <- map["title"]
   }
 }

0 个答案:

没有答案