ios - Fetching From CoreData returns AnyObject -


i fetching entity data coredata, returns anyobject, tried lot convert in nsdictionary , nsarray can not cast type.`

    var dictdata:nsdictionary?     let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate     let context = appdelegate.managedobjectcontext;     // self.selectedarray = response.objectforkey("retailers") as! nsarray;     let fetchrequest2 = nsfetchrequest()     let entitydescription2 = nsentitydescription.entityforname("offers", inmanagedobjectcontext: context)     fetchrequest2.entity  = entitydescription2      //fetchrequest2.returnsobjectsasfaults = false      {         let result2 : nsdictionary = try context.executefetchrequest(fetchrequest2) as! nsdictionary                    print("result:",result2)         result in (result2 as? nsdictionary)!{              if let data : nsdictionary = result as? nsdictionary{                  print(data)             } 

offer entity contains no of fields. kindly help. appreciated.

                print("result: ",result)                 print("dictdata:",dictdata) 

` }

context.executefetchrequest() returns [anyobject], not anyobject.

you need do:

if let results = context.executefetchrequest(fetchrequest2) as? [myobjecttype] {       object in results {         //do thing     }   } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo