ios - FetchRequest - NSArray element failed to match the Swift Array Element type - Swift 2.0 -
i want nsfetchrequest
display data uicollectionview
:
import uikit import coredata let appdelegate: appdelegate = uiapplication.sharedapplication().delegate as! appdelegate let context: nsmanagedobjectcontext = appdelegate.managedobjectcontext class garageviewcontroller: uiviewcontroller, uicollectionviewdelegate,uicollectionviewdatasource { @iboutlet weak var backgroundview: uiimageview! @iboutlet weak var collectionview: uicollectionview! var voitures: [voiture] = [voiture]() override func viewdidload() { super.viewdidload() collectionview.reloaddata() let fetchrequest = nsfetchrequest(entityname: "voiture") fetchrequest.resulttype = .dictionaryresulttype { try voitures = context.executefetchrequest(fetchrequest) as! [voiture] } catch let fetcherror nserror { print("voiturefetch error: \(fetcherror.localizeddescription)") } if (voitures.count > 0) { voiture in voitures [voiture] { print(voiture.nom!) } } else { print("aucune voiture") } }
when run code error :
fatal error: nsarray element failed match swift array element type
thank's !
Comments
Post a Comment