Enum element cannot be referenced as an instance member
I am creating an API layer using Moya and keep getting the above error for the target .updateMyWeightGoal
when I make a request for the endpoint.
goalAPI.request(target: .updateMyWeightGoal(weightGoalData: goalInfo), success: { (response) in
//
}){ (response: [String : Any]) in
print(response)
}
I created another Moya API of the same type and call it using the same goalAPI
one and it works fine.
Any ideas that might be causing this problem
For reference: class definition for type weightGoalData
class UpdatedWeightGoalInfo: Mappable {
var consumerUserID: Int?
var height: String?
var weight: String?
var goalWeight: String?
init() {
}
convenience init(userId: Int, weightGoalData: WeightGoalResponse) {
self.init()
consumerUserID = userId
height = "\(weightGoalData.currentHeight)"
weight = "\(weightGoalData.currentWeight)"
goalWeight = "\(weightGoalData.goalWeight)"
}
required init?(map: Map) {
}
func mapping(map: Map) {
consumerUserID <- map["consumerUserId"]
height <- map["height"]
weight <- map["weight"]
goalWeight <- map["goalWeight"]
}
}
And the API definition:
enum GoalSettingAPI: AccessTokenAuthorizable {
case updateMyWeightGoal(weightGoalData: UpdatedWeightGoalInfo)
}
extension GoalSettingAPI: TargetType {
var parameterEncoding: ParameterEncoding {
switch self {
default:
return JSONEncoding.default
}
}
var baseURL: URL { return URL(string: appBaseURL + "*hidden*/")! }
var path: String {
switch self {
case .updateMyWeightGoal(_):
return "updateMyWeightGoal"
}
}
var method: Moya.Method {
switch self {
case .updateMyWeightGoal(_):
return .post
}
}
var parameters: [String: Any]? {
switch self {
case .updateMyWeightGoal(let weightGoalData):
return weightGoalData.toJSON()
}
}
var sampleData: Data {
switch self {
default:
return Data()
}
}
var task: Task {
switch self {
default:
return .request
}
}
var shouldAuthorize: Bool {
switch self {
default:
return false
}
}
}
+5
source to share
3 answers