From 97667cd4424c2fcb8c1118b031823b1945ab9be4 Mon Sep 17 00:00:00 2001 From: tylerweitzman Date: Tue, 16 Jun 2015 11:02:31 -0700 Subject: [PATCH] Explain closure -bash --- P16-Implementing-Likes/content.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/P16-Implementing-Likes/content.md b/P16-Implementing-Likes/content.md index a450a89..c02cccd 100755 --- a/P16-Implementing-Likes/content.md +++ b/P16-Implementing-Likes/content.md @@ -361,6 +361,21 @@ Add the following method to the `Post` class: } 1. If the `toggleLikePost` method is called and a user likes a post, we unlike the post. First by removing the user from the local cache stored in the `likes` property, then by syncing the change with Parse. We remove the user from the local cache by using the `filter` method on the array stored in `likes.value`. + + You might be wondering what `$0` means. This symbol stands shorthand for the first parameter in a closure. The line + > + likes.value = likes.value?.filter { $0 != user } + > + + Is equivalent to: + + > + likes.value = likes.value?.filter { like in like != user } + > + + Similarly, `$1` would stand for the second parameter, and so on. + + 2. If the user doesn't like the post yet, we add them to the local cache and then synch the change with Parse. Great! Our changes to the `Post` class are complete. Next, we can make use of our new methods!