I'm using PHP to send data in JSON to create an array of custom objects in Swift. I've been told retrieveData() is bad code because it's in an infinite loop. I'm not sure on how to clean it up so it can be more efficient. On a side note, is there a way I can save the custom objects in an array that is easier to save to UserDefaults without NSCoder?

The app is basically a blog reader. It gets data from a server's database and displays it in a tableview.

\$\begingroup\$Yes, would be more cleaner way; I forgot this approach, I'll mention it\$\endgroup\$
– D4ttatrayaJun 13 '17 at 20:17

\$\begingroup\$A) I would retrieveData should only return an array of Blog. In an other method I would call this and set then thel mainArray with the result and reload data. If you change your source then you can easy exchange the call to retrieveData\$\endgroup\$
– mueschaJun 16 '17 at 1:40

\$\begingroup\$B) mainData is not set to empty before filling it up\$\endgroup\$
– mueschaJun 16 '17 at 1:41