-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathDiggerHelper.swift
More file actions
86 lines (58 loc) · 1.74 KB
/
DiggerHelper.swift
File metadata and controls
86 lines (58 loc) · 1.74 KB
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
79
80
81
82
83
84
85
//
// DiggerHelper.swift
// Digger
//
// Created by ant on 2017/10/26.
// Copyright © 2017年 github.cornerant. All rights reserved.
//
import Foundation
// MARK:- result help
public enum Result<T> {
case failure(Error)
case success(T)
}
// MARK:- error help
public let DiggerErrorDomain = "com.github.cornerAnt.DiggerErrorDomain"
public enum DiggerError: Int {
case badURL = 9981
case fileIsExist = 9982
case fileInfoError = 9983
case invalidStatusCode = 9984
case diskOutOfSpace = 9985
case downloadCanceled = -999
}
// MARK:- error help
public enum LogLevel {
case high,low,none
}
public func diggerLog<T>(_ info: T, file: NSString = #file, method: String = #function, line: Int = #line){
switch DiggerManager.shared.logLevel {
case .none:
_ = ""
case .low:
print("***************DiggerLog****************")
print("\(info)" + "\n")
case .high:
print("***************DiggerLog****************")
print( "file : " + "\(file.lastPathComponent)" + "\n"
+ "method : " + "\(method)" + "\n"
+ "line : " + "[\(line)]:" + "\n"
+ "info : " + "\(info)"
)
}
}
// MARK:- url helper
public protocol DiggerURL {
func asURL() throws -> URL
}
extension String: DiggerURL {
public func asURL() throws -> URL {
guard let url = URL(string: self) else { throw NSError(domain: DiggerErrorDomain, code: DiggerError.badURL.rawValue, userInfo: ["url":self]) }
return url
}
}
extension URL: DiggerURL {
public func asURL() throws -> URL {
return self
}
}