jessesquires / JSQMessagesViewController

An elegant messages UI library for iOS
https://www.jessesquires.com/blog/officially-deprecating-jsqmessagesviewcontroller/
Other
11.14k stars 2.81k forks source link

[Parse] Turning PFObject into JSQMessage #786

Closed kyco16 closed 9 years ago

kyco16 commented 9 years ago

I have posted my question on StackOverflow and I haven't got many views probably because this a complex question but here is the link to My StackOverflow question. I am having trouble with this JSQMessage. I know how to take a PFObject and put them into a TableView(tableviews are pretty much the same as CollectionViews) but I do not know to transfer over or assign the values from the PFObject to the ones in JSQMessage.

I looked at question #178 and I think that was for an older version of this library. I am still learning Objective-C, a good 6 months on my own, but I am absolutely riddled when it comes to this entire library and I really want to use it. I have posted code my entire .h and .m files on my StackOverflow question as well.

jessesquires commented 9 years ago

Hey @kyco16 - no worries :smile:

It looks like your messages is holding PFObjects. In that case, my answer from #178 applies.

(updated for latest version of the library)

Parse allows native subclasses now, so you don't have to use a plain PFObject. You should subclass PFObject, and simply have your object conform to the JSQMessageData protocol. There's no need to edit your existing fields/properties on your PFObject, just implement the methods in JSQMessageData and return the appropriate data.

Then, you can simply add your PFObject subclass to your local datasource. (i.e., don't use JSQMessage -- you already have your model objects)

I can't tell from your snippets, but it looks like self.messages contains might contain PFObjects, so the cast to JSQMessage won't work.

JSQMessageData: http://cocoadocs.org/docsets/JSQMessagesViewController/6.1.3/Protocols/JSQMessageData.html

Working with protocols: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html

kyco16 commented 9 years ago

@jessesquires Ah wow. You are really on point with these references. So what I should be doing is creating a custom class with a PFObject subclass and have that conform to the JSQMessageData protocol?

jessesquires commented 9 years ago

@kyco16 - exactly! let me know how that works out

kyco16 commented 9 years ago

Actually I just figured it out. I used this as reference since the project itself uses Parse as the backend and by looking at an example I realized what was going on.

Notification Chat: https://github.com/relatedcode/NotificationChat

It is a great reference for those are trying to use this library with the Parse backend

jessesquires commented 9 years ago

Thanks @kyco16 !

Please feel free to keep asking questions! :+1: