iphone - Updating/Inserting existing objects in NSFetchedResultsController -


i'm using nsfetchedresultscontroller uitableview displays list of folders , associated unread counts each item in folder. i'd insert/delete folders w/ animation tableview based on unread count during sync/refresh (on background thread utilizing nsmanagedobjectcontextdidsavenotification). folders no unread items should fade out, , existing folders new unread items should fade in.

currently using controller:didchangeobject:atindexpath:forchangetype:newindexpath: method not unless tableview reloaded, or app relaunched, not ideal.

is nsfetchedresultscontroller not way this? initial idea create separate core data entity holds folders unread items, , add/remove folders that, seems hokey.

my nspredicate looks like:

any items.unread == 1

update: above nspredicate works fine , grabs objects expect to. problem if app launches , folderx has 0 unread items, not appear. if refresh (goes out , parses json file in background thread) , folderx has 25 unread items, not automatically fade in or trigger nsfetchedresultschangeinsert , since wasn't included in first place, doesn't trigger nsfetchedresultschangeupdate why thought solution create separate entity holds folders unread items , add/remove during sync.

i feel i'm missing painfully obvious.

update 2: i've simplified problem as can removing influence of own app, i'm able replicate in default core data template in xcode.

the new problem: there single entity named "event" no relationships , 2 properties, "date" , "unreadcount". have nsfetchedresultscontroller set nspredicate looks like:

nspredicate *predicate = [nspredicate predicatewithformat:@"unreadcount < 10"]; 

every time new object added, created unreadcount of 15, existing objects decremented 1. done on separate managedobjectcontext (to replicate background processing, done on main thread).

i've implemented controllerwillchangecontent , related methods, , expected happen after existing object (with unreadcount of 15) decremented 5 times (to 10) should inserted tableview because matches predicate. not @ happens, object not appear @ unless app restarted.

i've attached sample project, run , click add button few times (nothing happen). restart app , see handful of objects in tableview, if click add button few more times objects remove themselves, new objects not added.

if nsfetchedresultscontroller not solution behavior work, is?

sample project: http://dl.dropbox.com/u/521075/bgupdating.zip

your predicate not work crossing 2 or more to-many relationships. have @ present:

type == folder , (set of folders).(set of items).unread == 1 

you can't use transverse arbitrary number of relationships. instead, need subquery like:

type == folder , (0!=subquery(folder,$f,0!=subquery($f.items,$i,$i.unread==1).@count).@count) 

i think maybe performing fetch on wrong entity. if presenting table of folder objects, should performing fetch on folder entity. alone simplify everything. predicate just:

any items.unread==1 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -