         guard !sharedInstance.fetching else { return }
         sharedInstance.fetching = true
         sharedInstance.fetchLgtmFromServer()
+    }
+    class func getFavoriteLgtms() -> [Lgtm] {
+        return sharedInstance.getFavoriteLgtms()
     }
 }
 /// private interfaces

//
import Alamofire
import AppKit

class Provider {
    var fetching = false
    static let sharedInstance:Provider = Provider()
    var stackLimit = 20
    var stack:[Lgtm] = []
    init() {
        stack.appendContentsOf(getLgtmFromRealm())
    }
}
/// static method interfaces
extension Provider {

import RealmSwift
/// interact with Realm
extension Provider {
    func getFavoriteLgtms() -> [Lgtm] {
        return favStack
    }
    private func fetchFromRealm() {
        let realm = getRealm()
        let urls = realm.objects(RealmLgtm).map{$0 as RealmLgtm}.map {$0.url}
        let targetUrls:[String]
        if urls.count > stackLimit {
            targetUrls = [] + urls[0...(stackLimit - 1)]
        } else {
            targetUrls = urls
        }
        for url in targetUrls {
            fetchImage(url) { [unowned self] image in
                let lgtm = Lgtm(url: url, image:image)
                self.favStack.append(lgtm)
            }
        }
    }
    private func saveToRealm(lgtm:Lgtm) {
        let data = RealmLgtm(lgtm: lgtm)
        let realm = getRealm()
        realm.write {
            realm.add(data, update: true)
        }
    }
    private func getRealm() -> Realm {
        let realm:Realm
        do {
            realm = try Realm()
        } catch {
            print(error)
            print(Realm.defaultPath)
            fatalError()
        }
        return realm
    }
}
class RealmLgtm : Object {
