-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPostActionsItem.swift
48 lines (38 loc) · 1.16 KB
/
PostActionsItem.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// PostActionsItem.swift
// Peach
//
// Created by Stephen Radford on 16/01/2016.
// Copyright © 2016 Cocoon Development Ltd. All rights reserved.
//
import Cocoa
import PeachKit
class PostActionsItem: NSCollectionViewItem {
@IBOutlet weak var likeBtn: NSButton!
@IBOutlet weak var likeCount: NSTextField!
@IBOutlet weak var commentCount: NSTextField!
var post: Post? {
didSet {
if let p = post {
likeBtn.state = (p.likedByMe) ? 1 : 0
if let count = p.likeCount {
likeCount.stringValue = "\(count)"
likeCount.sizeToFit()
}
if let count = p.commentCount {
commentCount.stringValue = "\(count)"
commentCount.sizeToFit()
}
}
}
}
@IBAction func likePost(sender: AnyObject) {
if let p = post {
p.like { error in
if let count = self.post?.likeCount {
self.likeCount.stringValue = "\(count)"
}
}
}
}
}