Created
October 19, 2016 04:40
-
-
Save rabimba/367e77c17419a6087a739963cc927aa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
// Dequeue cell | |
let cell = self.clientTable .dequeueReusableCell(withIdentifier: "tableViewCell", for: indexPath) | |
// Unpack message from Firebase DataSnapshot | |
let messageSnapshot: FIRDataSnapshot! = self.messages[indexPath.row] | |
let message = messageSnapshot.value as! Dictionary<String, String> | |
let name = message[Constants.MessageFields.name] as String! | |
if let imageURL = message[Constants.MessageFields.imageURL] { | |
if imageURL.hasPrefix("gs://") { | |
FIRStorage.storage().reference(forURL: imageURL).data(withMaxSize: INT64_MAX){ (data, error) in | |
if let error = error { | |
print("Error downloading: \(error)") | |
return | |
} | |
cell.imageView?.image = UIImage.init(data: data!) | |
} | |
} else if let URL = URL(string: imageURL), let data = try? Data(contentsOf: URL) { | |
cell.imageView?.image = UIImage.init(data: data) | |
} | |
cell.textLabel?.text = "sent by: \(name)" | |
} else { | |
let text = message[Constants.MessageFields.text] as String! | |
cell.textLabel?.text = name! + ": " + text! | |
cell.imageView?.image = UIImage(named: "ic_account_circle") | |
if let photoURL = message[Constants.MessageFields.photoURL], let URL = URL(string: photoURL), let data = try? Data(contentsOf: URL) { | |
cell.imageView?.image = UIImage(data: data) | |
} | |
} | |
return cell | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment