Search code examples
swiftparse-platform

Sort the posts in my feed from latest to oldest (using Swift and Parse)


I created a simple Instagram-like app using Parse. My problem is that the feed is organized with the oldest posts at the top of the feed and the latest posts at the bottom. How can I reverse the sorting order, so that posts are displayed from most recent at top to oldest at bottom?


Solution

  • You can also reverse your data array to

    let names: [String] = ["Apple", "Microsoft", "Sony", "Lenovo", "Asus"]
    
    var reversedNames = [String]()
    
    for arrayIndex in stride(from: names.count - 1, through: 0, by: -1) {
        reversedNames.append(names[arrayIndex])
    }