Here's a function:
func checkIfObjectsHaveCoordinates() {
PFQuery(className: "Products").findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> in
if error == nil && objects != nil {
for object in objects! {
if object["Latitude"] == nil || object["Longitude"] == nil {
self.convertObjectLocationToCoordinates(object)
}
object.pinInBackground()
}
} else {
print(error)
}
}
It checks if objects have a latitude or a longitude. If they don't, they will be passed to the convertObjectLocationToCoordinates
function. Either way, I save them locally, and this is why I think my function should't have side effects. I feel like this code is hardcoded in some way:
if myObject["Latitude"] == nil || myObject["Longitude"] == nil || myObject["Latitude"] as! Float == 0 || myObject["Longitude"] as! Float == 0
Does this function look good to you? Should I avoid side effects in my function?