-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.swift
79 lines (65 loc) · 2.74 KB
/
Extensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Extensions.swift
// LearnLab
//
// Created by Siddharth Kucheria on 5/21/19.
// Copyright © 2019 Siddharth Kucheria. All rights reserved.
//
import UIKit
import Firebase
let imageCache = NSCache<AnyObject, AnyObject>()
extension UIImageView{
func loadImageUsingCacheWithUrlString(urlString: String){
self.image = nil
//check cache for image first
if let cachedImage = imageCache.object(forKey: urlString as AnyObject){
self.image = cachedImage as! UIImage
return
}
// if let profileImageUrl = urlString{
let url = URL(string: urlString)
URLSession.shared.dataTask(with: url!, completionHandler: {(data, response, error) in
if error != nil{
print(error)
return
}
DispatchQueue.main.async {
if let downloadedImage = UIImage(data: data!) {
imageCache.setObject(downloadedImage, forKey: urlString as AnyObject)
self.image = downloadedImage
}
// self.image = UIImage(data: data!)
}
}).resume()
// }
}
}
extension UIViewController{
func getUserForUID(_ uid : String) -> User{
let user = User()
let ref = Database.database().reference()
ref.child("user").observeSingleEvent(of: .value
, with: { (snapshot) in
if let dictionary = snapshot.value as? [String : [String:Any]]{
for item in dictionary{
if(item.key == uid){
user.tutor = item.value["tutor"] as? String
user.email = item.value["email"] as? String
user.name = item.value["name"] as? String
user.profLinik = item.value["profilePic"] as? String
user.bio = item.value["bio"] as? String
user.courses = item.value["classes"] as? [String]
user.rating = item.value["rating"] as? NSNumber
user.id = item.key
user.rate = item.value["rate"] as? String
user.availability = item.value["availability"] as? String
user.fcmToken = item.value["fcmToken"] as? String
user.numReviews = item.value["numReviews"] as? Float
user.reviews = item.value["reviews"] as? [String]
}
}
}
})
return user
}
}