Skip to content

Instantly share code, notes, and snippets.

@aravindhkumar23
Created October 20, 2016 13:44
Show Gist options
  • Save aravindhkumar23/6569e38411d6ce6d3d0c31a3dc1f9f7f to your computer and use it in GitHub Desktop.
Save aravindhkumar23/6569e38411d6ce6d3d0c31a3dc1f9f7f to your computer and use it in GitHub Desktop.
sort dictionary inside array, and find match between 2 array
let loggedIn_array = ((loggedInUserSolution.valueForKey("solutions") as? NSArray ?? NSArray()).sort{
(($0 as? Dictionary<String, String> ?? Dictionary<String, String>())["solution_id"]) < (($1 as? Dictionary<String, String> ?? Dictionary<String, String>())["solution_id"])
}) as NSArray
let opposite_array = ((oppositeUserSolution.valueForKey("solutions") as? NSArray ?? NSArray()).sort{
(($0 as? Dictionary<String, String> ?? Dictionary<String, String>())["solution_id"]) < (($1 as? Dictionary<String, String> ?? Dictionary<String, String>())["solution_id"])
}) as NSArray
print("loggedIn_array ::\(loggedIn_array)")
print("opposite_array ::\(opposite_array)")
if (loggedIn_array.count == opposite_array.count) {
print("same count")
if(loggedIn_array == opposite_array){
print("same and match")
// redirect to Congragulation page
let vc:CongratulationViewController = CongratulationViewController()
self.navigationController?.showViewController(vc, sender: self)
} else {
print("same but doesnot match")
// redirect to DisputeSolutionViewController
let vc:DisputeSolutionViewController = DisputeSolutionViewController()
vc.disputeConversationId = conversationID
self.navigationController?.showViewController(vc, sender: self)
}
}else{
print("not a same count")
// array count not same
let vc:DisputeSolutionViewController = DisputeSolutionViewController()
vc.disputeConversationId = conversationID
self.navigationController?.showViewController(vc, sender: self)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment