Skip to content

Instantly share code, notes, and snippets.

View Salman544's full-sized avatar
🎯
Focusing

Muhammad Salman Salman544

🎯
Focusing
View GitHub Profile
import Foundation
struct User: Codable {
let id: String?
let name: String
let email: String
let phoneNumber: String
let password: String
let status: String?
@Salman544
Salman544 / NetworkRequest.swift
Created November 30, 2018 07:17
NSURLSession Code
class NetworkRequest {
static let shared = NetworkRequest()
private init() {}
func fetchJson<T: Decodable>(method: String = "GET",withUrl url: URL,json: Data? = nil, completion: @escaping (T) -> Void, error: ((String) -> Void)? = nil ) {
var request = URLRequest(url: url)
request.httpMethod = method
struct NetworkRequest<T: Decodable> {
public enum FetchResults {
case success(response: T)
case error(error: String)
}
static func fetchJson(with url: URL, completion: @escaping (FetchResults) -> Void) {