Post

Replies

Boosts

Views

Created

i don't get data from my server
my link works if I use postman to check if I receive data for the server and it works but my code doesn't work this is the data that I should receive [ { "id": "18", "profileName": "testProfiel24" }, { "id": "19", "profileName": "testProfiel25" }, { "id": "1021", "profileName": "testProfiel26" }, { "id": "1022", "profileName": "testProfiel27" }, { "id": "1023", "profileName": "testProfiel28" } ] func getData(){           let getToken : String? = KeychainWrapper.standard.string(forKey: "accessToken")                 let url = URL(string: "http://......./profile/load")!     let queryItems = [URLQueryItem(name: "token", value: getToken!)]     let newUrl = url.appending(queryItems)!     print(newUrl)           URLSession.shared.dataTask(with: newUrl, completionHandler: { data, response, error in                 guard let data = data,error == nil else{             print(error?.localizedDescription as Any)             return           }                 var result : Profile?                 do{             result = try JSONDecoder().decode(Profile.self, from: data)           }catch{                   print("failed to convert\(error.localizedDescription)")                 }                 guard let json = result else{             return           }                 print(json.id)           print(json.profileName)         }).resume()         } extension URL {   func appending(_ queryItems: [URLQueryItem]) -> URL? {     guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: true) else {       return nil     }     urlComponents.queryItems = (urlComponents.queryItems ?? []) + queryItems     return urlComponents.url   } } struct Profile : Decodable {   let id, profileName : String     }
8
0
1.7k
Dec ’20