swift - How to structure data for saving user comments? -


i using xcode program ios app. want set section in app users can leave comments. bit confused on how should go storing set of comments particular post. need save 3 things per comment. user's id, comment itself, , number of comment (ie first comment posted post, or second, third, etc...) not know how best save database. using parse-server primary database , issue while database can store multiple qualities objects, saving dictionary not possible. (i have wanted save info as):
desired strategy (but won't work)

var commentcount = 5 //will hold value of number of comments post var commentstring = "hello" var commenterid = "e1das312"   var commentsavingdict = [int: [string]]() func addcomment(){     commentcount = commentcount + 1     commentsavingdict[commentcount] = [commenterid, commentstring] } 

the issue in parse-dashboard arrays can saved, not dictionaries commentsavingdict is. considered merely saving string so:

2nd strategy

var commentcount = 5 //will hold value of number of comments post var commentstring = "hello" var commenterid = "e1das312"   var commentsavingarray = [string]() func addcomment(){     commentcount = commentcount + 1     commentsavingarray.append("\(commentcount) :::: \(commentstring) :::: \(commenterid)") } 

this approach work, require pulling each entry array, , separating string .split @ :::: positions, dumping each part 3 separate arrays , utilizing them way. take bit longer splitting need client side.

3rd strategy
final way conceived have each comment own object in database, 4 different qualities: number of comment, comment, post's id, , user's id. work, makes each comment own object, opposed being held in array of comments (as single object) particular post , think inefficient , use space quickly.

since cannot save dictionaries, there better approach problem have suggested? or incorrectly analyzing ones proposed?

your third strategy way go. in fact, parse ios developer's guide has pretty familiar example. each comment linked original post pointer. involve additional fetch when come retrieve comments post, more scalable attempting put comment objects inside array column on post itself. array columns more typically useful smaller, simpler collections.

this isn't without edge-case limitations. if want display count of comments on post in timeline, example, have fetch comments every post on screen. usual solution store counter on post itself, , update when comments added/removed (ideally via aftersave trigger in cloud code).

one additional note - can avoid storing 'comment number' , instead rely on comments createdat date. can retrieve comments filtering on post, , sorting creation date.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -