Recommand · May 23, 2021 0

Cannot specialize non-generic type 'Result'

I am trying to make a simple network call but I am getting error while using Result Type. Xcode is telling me that "Cannot specialize non-generic type ‘Result’". I am looking for the solution but was not successful finding it in the internet, nor in stackoverflow.
The error is:

Cannot specialize non-generic type 'Result'
Remove '<FriendsModel,NetworkingError>'

My code is: FriendsWebServices.swift

import Foundation

enum NetworkingError:Error{
    case nodataAvailable
    case invalidURL
    case canNotProcessData
    case encodingError
    case statusCodeIsNotOkay
}

class FriendsWebServices{
    static let shared = FriendsWebServices()
    private let session = URLSession.shared
    
    //Get Method
    func getPosts(completion: @escaping (Result<FriendsModel,NetworkingError>)->Void){
        let urlStirng = EndPointSouce.getEndPoint(type: .Base) + EndPointSouce.getEndPoint(type: .HowManyFriends(10))
        
        guard let url = URL(string: urlStirng) else {
            completion(.failure(.invalidURL))
            return
        }
        // Create the url request
        var request = URLRequest(url: url)
        request.httpMethod = "GET"
        
        let dataTask = session.dataTask(with: request) { data, response, error in
            guard let jsonData = data else{
                completion(.failure(.nodataAvailable))
                return
            }
            guard let response = response as? HTTPURLResponse else {
                print("Response is nil")
                return
            }
            if response.statusCode == 200{
                do{
                    let decoder = JSONDecoder()
                    let responseObject = try decoder.decode([Post].self, from: jsonData)
                    completion(.success(responseObject))
                }catch{
                    completion(.failure(.canNotProcessData))
                }
            }else{
                completion(.failure(.statusCodeIsNotOkay))
            }
            
        }
        
        dataTask.resume()
     }
    }

My Model :

import Foundation

struct FriendsModel:Decodable{
    var results: [Result]
}

struct Result:Decodable {
    var name: Name
    var location : Location
    var email: String
    var phone : String
    var cell: String
    var picture : Picture
}

struct Name:Decodable{
    var title: String
    var first: String
    var last: String
}

struct Location:Decodable {
    var street: String
    var city : String
    var state: String
    var postcode: String
    var timezone:TimeZone
}

struct TimeZone:Decodable {
    var offset: String
    var description: String
}

struct Picture:Decodable{
    var large : String
    var medium: String
    var thumbnail: String
}

Why I am getting this error? Thank You.