git.iko.soy/dashared/GDproject
on master help sign in
fixed news feed updates. added time for posts. have to detect correct time zone
commit78a2ade5f96788762536957055f623b22f106694 authorDarya Rednikina <rednikina.com@yandex.ru> dateSat 9 Mar 2019, 21:19 (8 years ago) parent1400778
4 files changed+24−3
GDproject/Controller/ News and channels/NewsController.swift+3 GDproject/Controller/ News and channels/NewsVC.swift+1 GDproject/Controller/ News and channels/PostViewCell.swift+5−3 GDproject/Simple model/Model.swift+15
GDproject/Controller/ News and channels/NewsController.swift+3
@@ -37,12 +37,14 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
3737 })
3838
3939 news.dataSourse = newPosts
40+ print("and heeeere in dict")
4041 tableView.reloadData()
4142 }
4243 }
4344
4445 var channel: Channel?{
4546 didSet{
47+ print(channel!.posts.count)
4648 navigationItem.title = channel?.title ?? ""
4749 }
4850 }
@@ -90,6 +92,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
9092 }
9193
9294 @objc func refreshPostsData( _ ff: UIRefreshControl){
95+ print("I am here")
9396 Model.getLast { [weak self] (tuple) in
9497 self?.channel = tuple.channel
9598 self?.dictionary = tuple.users
GDproject/Controller/ News and channels/NewsVC.swift+1
@@ -29,6 +29,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
2929
3030 var dataSourse: [Model.Posts] = []{
3131 didSet{
32+ cellDataSourse = []
3233 dataSourse.forEach { (item) in
3334 cellDataSourse.append(PostCellData(attributedData: PostCellData.create(with: item.body)))
3435 }
GDproject/Controller/ News and channels/PostViewCell.swift+5−3
@@ -31,7 +31,7 @@ class PostViewCell: UITableViewCell
3131 return label
3232 }()
3333
34− let commentsLabel: UILabel = {
34+ let timeLabel: UILabel = {
3535 let label = UILabel()
3636 label.font = UIFont.systemFont(ofSize: 12)
3737 label.textColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
@@ -84,6 +84,7 @@ class PostViewCell: UITableViewCell
8484 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.lastName ?? "")", for: .normal)
8585 nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
8686 fullNameLabel.text = "\(post.authorId)"
87+
8788 setUpInStackView(isFullVersoin)
8889 }
8990
@@ -151,10 +152,11 @@ class PostViewCell: UITableViewCell
151152
152153 stackView.edgesToSuperview(excluding: [.top, .bottom], insets: .left(16) + .right(16))
153154
154− let commentsSharesStackView = UIStackView(arrangedSubviews: [ commentsLabel, shareButton])
155+ let commentsSharesStackView = UIStackView(arrangedSubviews: [ timeLabel, shareButton])
155156 contentView.addSubview(commentsSharesStackView)
156157
157− commentsLabel.text = "14.02.19 в 23:00"
158+ timeLabel.text = post!.convertDateFormatter()
159+
158160 commentsSharesStackView.axis = .horizontal
159161 commentsSharesStackView.distribution = .equalSpacing
160162 commentsSharesStackView.edgesToSuperview(excluding: .top, insets: .bottom(10) + .left(16) + .right(16))
GDproject/Simple model/Model.swift+15
@@ -56,6 +56,21 @@ class Model{
5656 self.user = user
5757 self.updated = date
5858 }
59+
60+ func convertDateFormatter() -> String
61+ {
62+
63+ let dateFormatter = DateFormatter()
64+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format
65+ dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone!
66+ let date = dateFormatter.date(from: updated)
67+
68+ dateFormatter.dateFormat = "MMM d, yyyy HH:mm" ///this is what you want to convert format
69+ dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone!
70+ let timeStamp = dateFormatter.string(from: date!)
71+
72+ return timeStamp
73+ }
5974 }
6075
6176 struct Users: Codable{