Last Updated: February 25, 2016
·
746
· novalagung

iOS - Sort mutable array of views by each frame

NSComparator comparatorBlock = ^(UIView *obj1, UIView *obj2) {
    if (obj1.frame.origin.y > obj2.frame.origin.y) {
        return (NSComparisonResult)NSOrderedDescending;
    }

    if (obj1.frame.origin.y < obj2.frame.origin.y) {
        return (NSComparisonResult)NSOrderedAscending;
    }
    return (NSComparisonResult)NSOrderedSame;
};

[array sortUsingComparator:comparatorBlock];