ios - Converting fetchedResultsController into NSArray? -
i using (somessaging) https://github.com/socialobjects-software/somessaging
i want use code core datas fetchedresultscontroller
the problem when implementing messagesviewcontroller code above must return nsarray of messages this:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. self.myimage = [uiimage imagenamed:@"arturdev.jpg"]; self.partnerimage = [uiimage imagenamed:@"jobs.jpg"]; [self loadmessages]; } - (void)loadmessages { self.datasource = [[[contentmanager sharedmanager] generateconversation] mutablecopy]; } - (nsmutablearray *)messages { return self.datasource; } - (void)configuremessagecell:(somessagecell *)cell formessageatindex:(nsinteger)index { somessage *message = self.datasource[index]; // adjusting content 3pt. (in demo width of bubble's tail 3pt) if (!message.fromme) { cell.contentinsets = uiedgeinsetsmake(0, 3.0f, 0, 0); //move content 3 pt. right cell.textview.textcolor = [uicolor blackcolor]; } else { cell.contentinsets = uiedgeinsetsmake(0, 0, 0, 3.0f); //move content 3 pt. left cell.textview.textcolor = [uicolor whitecolor]; } cell.userimageview.layer.cornerradius = self.userimagesize.width/2; // fix user image position on top or bottom. cell.userimageview.autoresizingmask = message.fromme ? uiviewautoresizingflexibletopmargin : uiviewautoresizingflexiblebottommargin; // setting user images cell.userimage = message.fromme ? self.myimage : self.partnerimage; } example calls function generate sample messages: - (nsarray *)generateconversation { nsmutablearray *result = [nsmutablearray new]; nsarray *data = [nsarray arraywithcontentsofurl:[nsurl fileurlwithpath:[[nsbundle mainbundle] pathforresource:@"conversation" oftype:@"plist"]]]; (nsdictionary *msg in data) { somessage *message = [[somessage alloc] init]; message.fromme = [msg[@"fromme"] boolvalue]; message.text = msg[@"message"]; message.type = [self messagetypefromstring:msg[@"type"]]; message.date = [nsdate date]; int index = (int)[data indexofobject:msg]; if (index > 0) { somessage *prevmesage = result.lastobject; message.date = [nsdate datewithtimeinterval:((index % 2) ? 2 * 24 * 60 * 60 : 120) sincedate:prevmesage.date]; } if (message.type == somessagetypephoto) { message.media = uiimagejpegrepresentation([uiimage imagenamed:msg[@"image"]], 1); } else if (message.type == somessagetypevideo) { message.media = [nsdata datawithcontentsoffile:[[nsbundle mainbundle] pathforresource:msg[@"video"] oftype:@"mp4"]]; message.thumbnail = [uiimage imagenamed:msg[@"thumbnail"]]; } [result addobject:message]; } return result; }
meaning messages in message array have somessage objects.
i want use core data im going using fetchedresultscontroller how can load data fetchedresultscontroller.
i dont want start converting nsarray because im not sure happen when more data added , data reloaded.
would great if give me code examples out.
if want see full code available on github can see how works.
Comments
Post a Comment