Skip to content

Commit

Permalink
decode to date object, slip onw step in string extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 12, 2020
1 parent 93bf59a commit 709b777
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
Binary file not shown.
3 changes: 3 additions & 0 deletions GHFollowers/Extensions/Date+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import Foundation


// MARK: THIS IS NOT USED ANYMORE SINCE WE CONVERTED - DECODED THE STRING WE RECIEVE FROM THE API INTO A DATE FORMAT IN THE NETWORK MANAGER


extension Date {

func convertToMonthYearFormat() -> String {
Expand Down
2 changes: 2 additions & 0 deletions GHFollowers/Managers/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class NetworkManager {
let decoder = JSONDecoder()
// convert keys from snake_case to camelCase
decoder.keyDecodingStrategy = .convertFromSnakeCase
// convert date to a standard Date format
decoder.dateDecodingStrategy = .iso8601
// array we want to create its type from the data constant from above
let user = try decoder.decode(User.self, from: data)
// if all ok call the completed callback, passing the array and nil for error
Expand Down
2 changes: 1 addition & 1 deletion GHFollowers/Model/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ struct User: Codable {
let htmlUrl: String
let following: Int
let followers: Int
let createdAt: String
let createdAt: Date
}
2 changes: 1 addition & 1 deletion GHFollowers/Screens/UserInfoVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class UserInfoVC: UIViewController {
self.add(childVC: GFUserInfoheaderVC(user: user), to: self.headerView)
self.add(childVC: repoItemVC, to: self.itemViewOne)
self.add(childVC: followerItemVC, to: self.itemViewTwo)
self.dateLabel.text = "GitHub since \(user.createdAt.convertToDisplayFormat())"
self.dateLabel.text = "GitHub since \(user.createdAt.convertToMonthYearFormat())"
}


Expand Down

0 comments on commit 709b777

Please sign in to comment.