-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserDataManager.swift
39 lines (33 loc) · 1.01 KB
/
UserDataManager.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
//
// UserDataManager.swift
// AutoLayoutAnimation
//
// Created by Ozgur Vatansever on 10/27/15.
// Copyright © 2015 Techshed. All rights reserved.
//
import UIKit
enum UserDataHTTPResponse {
case success([User])
case error(NSError)
}
class UserDataManager {
fileprivate let dataSource = UserDataSource()
fileprivate static let shared = UserDataManager()
class func sharedInstance() -> UserDataManager {
return self.shared
}
func requestUsers(_ plist: String, completion: (UserDataHTTPResponse) -> Void) {
execute(delay: 1.0, repeating: false) {
if let users = self.dataSource.loadUsersFromPlist(named: plist) {
completion(.success(users))
}
else {
let userInfo = [
NSLocalizedDescriptionKey: "Plist not found or failed to parse.",
NSLocalizedFailureReasonErrorKey: "Plist not found or failed to parse."
]
completion(.error(NSError(domain: "UserDataManagerErrorDomain", code: -999, userInfo: userInfo)))
}
}
}
}