@@ -60,16 +60,19 @@ class MessageViewModel {
6060 }
6161 }
6262
63- fileprivate func getUserData( ) {
64- DispatchQueue . global ( qos: . background ) . async { [ weak self] in
63+ func getUserData( ) {
64+ DispatchQueue . global ( qos: . default ) . async { [ weak self] in
6565 self ? . getDataFromFile ( fileName: " user " ) { ( userResponse: [ User ] , _) in
6666 self ? . users = userResponse
6767 }
6868 }
6969 }
7070
71- fileprivate func getDataFromFile< T> ( fileName: String , completion: ( _ data: [ T ] , _ pagination: Pagination ) -> ( ) ) where T: Mappable {
72- guard let jsonData = Data . dataFromJSONFile ( fileName) else { return }
71+ private func getDataFromFile< T> ( fileName: String , completion: ( _ data: [ T ] , _ pagination: Pagination ? ) -> ( ) ) where T: Mappable {
72+ guard let jsonData = Data . dataFromJSONFile ( fileName) else {
73+ completion ( [ ] , nil )
74+ return
75+ }
7376
7477 do {
7578 let jsonObj = try JSON ( data: jsonData)
@@ -79,9 +82,10 @@ class MessageViewModel {
7982 return
8083 }
8184
82- completion ( listReponse. data, listReponse. pagination! )
85+ completion ( listReponse. data, listReponse. pagination)
8386 } catch {
8487 print ( " Error \( error) " )
88+ completion ( [ ] , nil )
8589 return
8690 }
8791 }
@@ -132,7 +136,7 @@ extension MessageViewModel {
132136 return . single
133137 }
134138
135- fileprivate func handleDataSource( messages: [ Message ] ) -> [ Message ] {
139+ private func handleDataSource( messages: [ Message ] ) -> [ Message ] {
136140 let modifiedArray = messages. map { msg -> Message in
137141 var m = msg
138142 m. isOutgoing = self . isOutgoingMessage ( m)
@@ -142,15 +146,15 @@ extension MessageViewModel {
142146 return modifiedArray
143147 }
144148
145- fileprivate func isOutgoingMessage( _ message: Message ) -> Bool {
149+ private func isOutgoingMessage( _ message: Message ) -> Bool {
146150 guard let user = currentUser else {
147151 return false
148152 }
149153
150154 return message. sendByID == user. id
151155 }
152156
153- fileprivate func getIndexPathWillAdds( newDataSize: Int ) -> [ IndexPath ] {
157+ private func getIndexPathWillAdds( newDataSize: Int ) -> [ IndexPath ] {
154158 let currentNumberMessage = messages. count
155159 let newNumberMessage = messages. count + newDataSize
156160 var indexPathWillAdds : [ IndexPath ] = [ ]
0 commit comments