Created
June 14, 2019 11:05
-
-
Save chaitanyaSoni96/d4cc893bff581b3065fc07166180ae8d to your computer and use it in GitHub Desktop.
Array Extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSArray{ | |
//sorting- ascending | |
func ascendingArrayWithKeyValue(key:String) -> NSArray{ | |
let ns = NSSortDescriptor.init(key: key, ascending: true) | |
let aa = NSArray(object: ns) | |
let arrResult = self.sortedArray(using: aa as! [NSSortDescriptor]) | |
return arrResult as NSArray | |
} | |
//sorting - descending | |
func discendingArrayWithKeyValue(key:String) -> NSArray{ | |
let ns = NSSortDescriptor.init(key: key, ascending: false) | |
let aa = NSArray(object: ns) | |
let arrResult = self.sortedArray(using: aa as! [NSSortDescriptor]) | |
return arrResult as NSArray | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array where Element:Equatable { | |
func removeDuplicates() -> [Element] { | |
var result = [Element]() | |
for value in self { | |
if result.contains(value) == false { | |
result.append(value) | |
} | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment