0

Ive been searching for at-least an hour with no luck. There are a lot of question similar to this one but that do not give the correct answer.

What I'm trying to do is simply I have an array for a notifications table:

Code:

var notificationList = [(Type: "Work", Date: "7/7/7", Seen: false), (Type: "Home", Date: "8/8/8", Seen: false),(Type: "Fun", Date: "9/9/9", Seen: false)]

It has the value specifying the type of notification it will be, the date it was created and if it has been seen or not.

I can append a new notification to the list by using this.

Code:

 notificationList.append((Type: "Work", Date: "8/8/8", Seen: false))

The problem that I'm trying to find out how to solve is. If I can search for the slot called Date and then say remove all index's that have the string 8/8/8 in the date slot.

Seems simple enough haha.

So far I can do this but this code will make me match every single slot in the array in order for it to work.

Code:

notificationList = notificationList.filter(){$0 != (Type: "Work", Date: "8/8/8", Seen: false)}

1 Answer 1

1

To filter for all notifications whose Date is not "8/8/8" write

notificationList = notificationList.filter{ $0.Date != "8/8/8" }

It's highly recommended to use

  • A struct rather than a tuple
  • Lowercased parameter labels / variables since Date can be confused with the struct Date in Swift 3
Sign up to request clarification or add additional context in comments.

1 Comment

Wow that it lol thanks. its work all I had to do is add ($0.date).

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.