我需要调用get api,为此我需要在api调用中追加参数。但我的问题是我在以前的视图api的响应中得到了那个参数。 现在我有这个字典作为回应
Employee Detail Info {
"business_unit_3" = "South Europe";
"currency_type" = TRY;
"date_of_joining" = "01-Nov-10";
desig = "KEY ACCOUNT MANAGER";
email = "try-employee-16@aw.com";
"emp_salary_status" = 1;
"final_salary" = "241455.28";
"first_approver" = "TRY-Employee-10@aw.com";
"fourth_approver" = "TRY-Employee-5@aw.com";
grade = 3;
id = 134;
"increment_applied_on_salary" = "227788.00";
"last_action_by" = "TRY-Employee-10@aw.com";
"last_manager_name" = "TRY-Employee-10";
level = 3A;
"manager_discretions" = "6.00";
"manager_emailid" = "TRY-Employee-10@aw.com";
"market_salary" = "0.00";
name = "TRY-Employee-16";
"performance_cycle_name" = AW;
"performance_rating" = "Exceeds Results";
"req_status" = 1;
"rule_id" = 1;
"rule_name" = "AW Sal";
"rule_staus" = 6;
"second_approver" = "TRY-Employee-3@aw.com";
"tbl_pk_id" = 133;
"third_approver" = "TRY-Employee-5@aw.com";
"upload_id" = 1;
}
我需要从这个字典中获取id,rule id和upload id,并在我的第二个api的调用中附加这些值。我不确定我会收到什么类型的数据,所以我采取了“任何”
为此我写了我的代码
func getSalaryReviewDetailApi()
{
var userID:Any = 0
var ruleID :Any = 0
var uploadID :Any = 0
// Get paramters from dict
if (self.dictEmployeeDetail.object(forKey: "id") != nil){
userID = self.dictEmployeeDetail.object(forKey: "id") as Any
}
if (self.dictEmployeeDetail.object(forKey: "rule_id") != nil){
ruleID = self.dictEmployeeDetail.object(forKey: "rule_id") as Any
}
if(self.dictEmployeeDetail.object(forKey: "upload_id") != nil){
uploadID = self.dictEmployeeDetail.object(forKey: "upload_id") as Any
}
let apiToContact = ApiConstants.UrlBase+ApiConstants.EndPointGetSalaryReviewDetail+"\(userID)/\(ruleID)/\(uploadID)"
print("Api Calling \(apiToContact)")
}
但在打印时
我得到了这个
https://test.company.in/user-portal/api/team/employeeincrement/Optional(134)/Optional(1)/Optional(1)
如何从这里删除可选项并获取它的实际值。
由于
答案 0 :(得分:1)
试试这个,
state.isVisible
<强>更新强>
let apiToContact = ApiConstants.UrlBase+ApiConstants.EndPointGetSalaryReviewDetail+"\(userID!)/\(ruleID!)/\(uploadID!)"
替代方法,
if (self.dictEmployeeDetail.object(forKey: "id") != nil){
userID = self.dictEmployeeDetail.object(forKey: "id") as Int
}