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 !

i had same problem. issue due not setting class property entity in model file.

enter image description here


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -