I created a swift xcframework with a single public func:
public func getClientWithCompletion(clientId: String, completion: @escaping (Result<Client, Error>) -> Void) {
let urlString = "https://api-here.com"
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, resp, err) in
if let err = err {
completion(.failure(err))
return
}
do {
let client = try JSONDecoder().decode(Client.self, from: data!)
print("client: ", client)
print("client name: ", client.name)
completion(.success(client))
} catch let jsonError {
completion(.failure(jsonError))
}
}.resume()
}
The two print statements look correct. I'm seeing the client:
Client(name: "Blueprint")
and the client name:
Blueprint
Here is the Client struct
public struct Client {
let name: String
}
extension Client: Codable {
enum CodingKeys: String, CodingKey {
case name
}
}
However, when I call this function from a demo project I'm not able to access the member name
:
astra.getClientWithCompletion(clientId: "7ce19ab3d29c4680b1f9e7e135472bec") { res in
switch res {
case .success(let client):
print(client) <-- prints fine
print("new way of showing client: ", client.name) <-- Value of type 'Client' has no member 'name'
case .failure(let error):
print("failure: ", error)
}
}
What is going on here where I can't access the name member of Client on the demo app?
question from:
https://stackoverflow.com/questions/65894244/swift-5-value-of-type-has-no-member 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…