ios - Getting objects from NSSet and populating TableView -


i have piece of code shown below

func getitemsonlist(){      let app = uiapplication.shared.delegate as! appdelegate     let context = app.persistentcontainer.viewcontext      //fetchrequest list     let fetchrequest = nsfetchrequest<nsfetchrequestresult>(entityname: "list")     let predicate = nspredicate(format: "title == %@", listname)     fetchrequest.returnsobjectsasfaults = false     fetchrequest.predicate = predicate      if let fetchresults = try? context.fetch(fetchrequest){         if fetchresults.count > 0 {             listentity in fetchresults {                 let list = listentity as! list                 print(list.title any)                 itemsonlistset = list.contains! 

what gets items specified list using .contains relationship between 2 entities, , saves items in nsset.

what want populate tableview objects in nsset.

is there function related nsset allows me items set? or should save items in array instead of nsset.

p.s. .contains relationship of type nsset

    @nsmanaged public var contains: nsset? 

why don't convert set array using,

if let _ = list.contains {     let itemsonlistarray = list.contains!.allobjects  } 

else

if let unwrappedlist = list.contains {         let itemsonlistarray = unwrappedlist.allobjects  } 

now use itemsonlistarray tableview's data source :)

edit:

your code

let item = itemsonlistarray[indexpath.row]  cell.textlabel?.text = item as? string 

assumes itemsonlistarray array of strings!!! absolutely impossible because list.contains! set of nsmanagedobjects or if created mapped subclasses of managedobjects contain set of managed objects items.

what should doing (because have not provided description of item assuming item has name property in it)

let item = itemsonlistarray[indexpath.row] as! item cell.textlabel?.text = item.name 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -