I am creating a user request model to pass-params for web service call
- toRegisterParams() is used call register web service request
toLoginParams() is used call register web service request
so my question is this correct way or I need to Optimise my code or I should make different models for the same. As most-of parameters are the same.
for example, if I need add param in login service there are more probability to add the same in register service param.
struct UserResquest { var phone: String = "" var countryPhoneCode: String = "" var referralCode: String = "" var firstName : String = "" var lastName : String = "" var email: String = "" var country: String = "" var loginBy: String = CONSTANT.MANUAL var socialUniqueID: String = "" var password: String = "" /** * Instantiate the instance using the passed dictionary values to set the properties values */ func toRegisterParams() -> [String:Any] { var dictParam: [String:Any] = [:] dictParam[PARAMS.PHONE] = phone dictParam[PARAMS.COUNTRY_PHONE_CODE] = countryPhoneCode dictParam[PARAMS.APP_VERSION] = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String) dictParam[PARAMS.EMAIL] = email dictParam[PARAMS.LAST_NAME] = firstName dictParam[PARAMS.FIRST_NAME] = lastName dictParam[PARAMS.DEVICE_TOKEN] = preferenceHelper.getDeviceToken() dictParam[PARAMS.DEVICE_TYPE] = CONSTANT.IOS dictParam[PARAMS.DEVICE_TIMEZONE] = TimeZone.current.identifier dictParam[PARAMS.COUNTRY] = country dictParam[PARAMS.LOGIN_BY] = loginBy if loginBy != CONSTANT.MANUAL { dictParam[PARAMS.SOCIAL_UNIQUE_ID] = socialUniqueID dictParam[PARAMS.PASSWORD] = "" } else { dictParam[PARAMS.SOCIAL_UNIQUE_ID] = "" dictParam[PARAMS.PASSWORD] = password } return dictParam } func toLoginParams() { var dictParam: [String:Any] = [:] dictParam[PARAMS.APP_VERSION] = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String) dictParam[PARAMS.EMAIL] = phone dictParam[PARAMS.COUNTRY_PHONE_CODE] = countryPhoneCode dictParam[PARAMS.DEVICE_TIMEZONE] = TimeZone.current.identifier dictParam[PARAMS.DEVICE_TYPE] = CONSTANT.IOS dictParam[PARAMS.SOCIAL_UNIQUE_ID] = "" dictParam[PARAMS.DEVICE_TOKEN] = preferenceHelper.getDeviceToken() dictParam[PARAMS.LOGIN_BY] = CONSTANT.MANUAL dictParam[PARAMS.PASSWORD] = password dictParam[PARAMS.PHONE] = phone return dictParam } }
let me explain the scenario
in my app user can login throught phone number - in first screen user inputs the mobile number and place submit button (which call api and check number exist or not)
if yes then password screen will display when user enter password login api call with above params
If number is not registered register screen will display with entered mobile number and then user can't edit number as it verified by otp. after fill form register api call with above param.
toRegisterParams()
andtoLoginParams()
are described as “used call register web service request” – copy/paste error? \$\endgroup\$dictParam[PARAMS.EMAIL] = phone
a typo? \$\endgroup\$