I am getting parameter value from other viewcontroller, and i am getting parameter valueperfectly but which i am unable to add to API
here if i hardcode eventStatus
then its working
and eventStatus
value from otherviewcontroller also coming perfectly which i am unable to add to API
if i hard code like this its working
var eventType = "Draft"
let string = Constants.GLOBAL_URL + "/get/allevents/?eventstatus=(self.eventType)"
Code: here i am getting correct eventStatus
value but while breakpoint its control goes to else, why?
class EventsViewController: UIViewController {
var eventsListArray = [AnyObject]()
// var eventType = "Draft"
var eventType: String!
var eventList : EventsModel? = nil
@IBOutlet weak var eventsTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
getAllEventsList()
}
func getAllEventsList() {
DispatchQueue.main.async {
let headers = ["deviceid": deviceId,"userType": "personal","key": personalId]
DispatchQueue.main.async {
//let string = Constants.GLOBAL_URL + "/get/allevents/?eventstatus=(self.eventType)"
let string = Constants.GLOBAL_URL + "/get/allevents"
var urlComponents = URLComponents(string: string)
let eventStatus = self.eventType
print("event status value in API call (eventStatus)")
let requestEventType = URLQueryItem(name: "eventstatus", value: eventStatus)
urlComponents?.queryItems = [requestEventType]
let urlStr = urlComponents?.url
var request = URLRequest(url: urlStr!, cachePolicy: .useProtocolCachePolicy,timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers as! [String : String]
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
DispatchQueue.main.async {
if error == nil {
let httpResponse = response as? HTTPURLResponse
if httpResponse!.statusCode == 200 {
do {
let jsonObject = try JSONSerialization.jsonObject(with: data!) as! [String :Any]
print("publish event (jsonObject)")
self.eventList = EventsModel.init(fromDictionary: jsonObject)
DispatchQueue.main.async {
if self.eventList?.events.count != 0 {
DispatchQueue.main.async {
self.eventsTableView.reloadData()
}
}
else {
DispatchQueue.main.async {
Constants.showAlertView(alertViewTitle: "", Message: "No Events (self.eventType)", on: self)
self.eventList?.events.removeAll()
self.eventsTableView.reloadData()
}
}
}
} catch { print(error.localizedDescription) }
} else {
Constants.showAlertView(alertViewTitle: "", Message: "Something went wrong, Please try again", on: self)
}
}
}
})
dataTask.resume()
}
}
}
}
where i am wrong, why eventStatus
value not adding to API.. please suggest me
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…