0

I have an Array of Strings as shown:

enter image description here

I also have an array of objects that contain:

enter image description here

When I run the following line:

let filterNo = self.responseObjs.filter({!formItemIds.contains(String(describing: $0.formItemId))})

I expect filterNo to be empty as all the formItemIds are contained in the array. It is however not removing any of the items. Am I missing something basic?

enter image description here

1 Answer 1

1

Remove the describing from the init of String and use Nil-Coalescing Operator with $0.formItemId to unwrapped optional.

let filterNo = self.responseObjs.filter({!formItemIds.contains(String($0.formItemId ?? 0))})

You are not getting filtered data because your formItemId property is optional and using String(describing: $0.formItemId) give you output like Optional(98)

Sign up to request clarification or add additional context in comments.

1 Comment

@Alan Welcome mate :)

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.