2016-07-03 11 views
0

私は迅速に従うよう、タイプ「AnyObject?」の値を変換できません。指定されたタイプの 'BookingObject!'

import Foundation 

class BookingObject { 
    var bookingTitle: String = "" 
    var bookingDesc: String = "" 
} 

が、その後続く

private var bookingData:NSMutableArray? 
for country in countryCode { 
    bookingObj.bookingTitle = country.name 
    bookingObj.bookingDesc = country.name 
    bookingData?.addObject(bookingObj) 
} 

や問題が値

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    /* error found that line */ 
    let bookingObj:BookingObject! = bookingData?.objectAtIndex(indexPath.row) 
    let cell = bookingTable.dequeueReusableCellWithIdentifier("BookCell", forIndexPath: indexPath) as! BookCell 
    cell.lbAppointmentTitle.text = bookingObj.bookingTitle 
    return cell 
} 

を取得する場合は、次の持っているように私に知らせてくださいデータを追加予約オブジェクトを作成しました私が間違ってそのエラーを漏らしたのです

タイプ「AnyObject?」の値を変換できません。指定されたタイプ 'BookingObject!'

struct Booking : CustomStringConvertible { 
    let title : String 
    var description : String { return title } 
} 

はこのようbookingsプロパティを宣言します:

private var bookings : [BookingObject] = [] 

次のように項目を追加します。

for country in countryCode { 
    bookings(Booking(title: country.name)) 
} 

をあなたのアイテムをゲット

答えて

0

構造体とCustomStringConvertibleプロトコルを使用しますこのように:

let booking = bookings[indexPath.row] 
0

Kametrixomの回答がうまくいくはずです。具体的な問題は配列の宣言で、[BookingObject]でなければなりません。クラスオブジェクトには参照セマンティクスがあり、そのうちの1つしか持たないため、他の変更が必要です。

関連する問題