This file contains hidden or 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
enum Router: URLRequestConvertible { | |
case getProducts(pageSize: Int, page: Int) | |
case deleteProduct(idx: Int) | |
var baseURL: URL { | |
return URL(string: "https://api.service.com")! | |
} | |
var method: HTTPMethod { | |
switch self { |
This file contains hidden or 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 getProducts(pageSize: Int, | |
page: Int, | |
completion: @escaping (Result<[Product], Error>) -> Void) { | |
var headers: HTTPHeaders = [] | |
if let accessToken = KeychainService.loadAccessToken() { | |
headers["Autorization"] = "Bearer \(accessToken)" | |
} | |
let parameters: [String: Any] = [ |
This file contains hidden or 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
class User: Serializable { | |
@Serialized | |
var idx: Int | |
@Serialized("user_name") | |
var name: String | |
@Serialized(alternateKey: "mobileNumber") | |
var phoneNumber: String? | |
This file contains hidden or 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
struct User: Codable { | |
var idx: Int | |
var name: String | |
enum CodingKeys: String, CodingKey { | |
var idx = "user_idx" | |
var name = "user_name" | |
} | |
init(from decoder: Decoder) throws { |
This file contains hidden or 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
struct BundleResource { | |
@BundleResourceWrapper(decoder: { String(data: $0, encoding: .utf8) }, name: "License", type: "txt") | |
static var licenseText: String? | |
@BundleResourceWrapper(decoder: { UIImage(data: $0) }, name: "thumbnail", type: "jpg") | |
static var thumbnail: UIImage? | |
} |
This file contains hidden or 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
@propertyWrapper | |
struct BundleResourceWrapper<Resource> { | |
typealias DecodeHandler = (Data) -> Resource | |
let decoder: DecodeHandler | |
let fileManager: FileManager = .default | |
let bundle: Bundle = .main | |
let name: String | |
let type: String |
This file contains hidden or 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
if let path = Bundle.main.path(forResource: "License", ofType: "txt"), | |
let data = FileManager.default.contents(atPath: path), | |
let txt = String(data: data, encoding: .utf8) { | |
// ... | |
} |
This file contains hidden or 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
Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String |
This file contains hidden or 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
GlobalSetting.isRegistered = true | |
if GlobalSetting.isRegistered { | |
// ... | |
} |
This file contains hidden or 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
struct GlobalSetting { | |
@UserDefaultsWrapper(key: "isRegistered", defaultValue: false) | |
static var isRegistered: Bool | |
} |