Skip to content

Commit

Permalink
complete homework 4
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-bor committed Oct 16, 2017
1 parent 28c44cd commit 2b5197c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ extension ConversationDataSource: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let message = conversation.messages[indexPath.row]
let identifier = message.type == .incoming ? CellIdentifier.incomingCellIdentifier : CellIdentifier.outgoingCellIdentifier
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! MessageCell
cell.message = message.text
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)
if let cell = cell as? MessageCellConfiguration {
cell.message = message.text
}
return cell
}
}
2 changes: 1 addition & 1 deletion TinkoffChat/Conversation/View/MessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class MessageCell: UITableViewCell {
class MessageCell: UITableViewCell, MessageCellConfiguration {
var message: String? {
didSet {
messageLabel.text = message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
import UIKit

protocol MessageCellConfiguration: class {
var text: String? { get set }
var message: String? { get set }
}
292 changes: 30 additions & 262 deletions TinkoffChat/Current User Profile/Base.lproj/Profile.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ProfileViewController: UIViewController {
private let gcdDataManager = GCDDataManager()
private let operationDataManager = OperationDataManager()

// MARK: View life cycle
// MARK: - View life cycle

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -84,14 +84,14 @@ class ProfileViewController: UIViewController {

private func loadUserProfile() {
activityIndicator.startAnimating()
let profileDataManager = getRandomProfileDataManager()
let profileDataManager = getRandomProfileDataManager() // randomly read with GCD or Operation
profileDataManager.loadUserProfile { [unowned self] profile, error in
self.activityIndicator.stopAnimating()
if let loadedProfile = profile {
self.originalProfile = loadedProfile
self.modifiedProfile = loadedProfile
} else {
self.updateUI()
self.updateUI()
}
if error != nil {
self.handleDataOperationError(error!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FileBasedStorage {

enum FileBasedStorageError: Error {
case corruptedData
case profileNotFound
}

func save(_ profile: UserProfile) throws {
Expand All @@ -34,7 +35,7 @@ class FileBasedStorage {

func loadUserProfile() throws -> UserProfile? {
guard fileManager.fileExists(atPath: filePath.path) else {
throw FileBasedStorageError.corruptedData
throw FileBasedStorageError.profileNotFound
}
let data = try Data(contentsOf: filePath)
let profile = try deserializeUserProfile(from: data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

class GCDDataManager: ProfileDataManager {
private let serialQueue = DispatchQueue(label: "com.nikitaborodulin.gcdDataManagerQueue")
private let serialQueue = DispatchQueue(label: "com.nikitaborodulin.TinkoffChat.gcdDataManagerQueue")
private let dataStorage = FileBasedStorage()

func save(_ profile: UserProfile, completion: @escaping (Bool, Error?) -> Void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class OperationDataManager: ProfileDataManager {
private let queue = OperationQueue()
private let dataStorage = FileBasedStorage()


func save(_ profile: UserProfile, completion: @escaping (Bool, Error?) -> Void) {
let saveOperation = SaveProfileOperation(with: profile, dataStorage: dataStorage, completion: completion)
queue.addOperation(saveOperation)
Expand Down

0 comments on commit 2b5197c

Please sign in to comment.