1

I am converting my code from swift 3.2 to swift 4 and I am getting error for this code

self.arrData = json.sorted{ $0.0.1["chkincount"].doubleValue > $0.1.1["chkincount"].doubleValue }.map { $0.1 }

Contextual closure type '((String, JSON), (String, JSON)) -> Bool' expects 2 arguments, but 1 was used in closure body

How to fix this ?

3

1 Answer 1

2

In sorted closure changed $0.0.1 with $0.1 to access first closure argument and $0.1.1 with $1.1 to access second closure argument after making this changes you all set to go.

self.arrData = json.sorted{ $0.1["chkincount"].doubleValue > $1.1["chkincount"].doubleValue }.map { $0.1 }
Sign up to request clarification or add additional context in comments.

4 Comments

Can you please explain why this code is working in swift 4 and above is not working ?
@VarunNaharia I have already write in my answer that you haven't access the second argument $1 in your closure so you need to access that instead of $0.1 it is $1 as of $0 and $1 represent (String, JSON) not the ((String,JSON),(String,JSON))
@VarunNaharia May be they have changed that in Swift 4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.