2017-07-23 11 views
6

मैं इस तरह की एक पोस्ट शरीर पैरामीटर:विषम संग्रह शाब्दिक केवल '[स्ट्रिंग: कोई भी]' का अनुमान लगाया जा सकता है; स्पष्ट प्रकार टिप्पणी जोड़ने अगर यह जानबूझकर है

{ 
    "id": 0, 
    "name": "string", 
    "contactInfo": "string", 
    "message": "string" 
} 

तो के बाद से मैं Alamofire उपयोग कर रहा हूँ मापदंडों पोस्ट करने के लिए मैं इस तरह के बाद शरीर शब्दकोश का वर्णन कर रहा हूँ:

let body = ["id": userID, "name": userName, "contactInfo": contactInfo, "message": message] 

class func postUserFeedback(userID: Int, userName: String, contactInfo: String, message: String,completionHandler: @escaping (FeedbackResponse?) -> Void) { 
    let body = ["id": userID, "name": userName, "contactInfo": contactInfo, "message": message] 
    request(route: .userFeedback, body: body).responseObject { (response: DataResponse<FeedbackResponse>) in 

     response.result.ifSuccess({ 
     completionHandler(response.result.value) 
     }) 

     response.result.ifFailure { 
     completionHandler(nil) 
     } 
    } 

    } 

लेकिन मैं हो रही है इस तरह त्रुटि: Error screenshot

क्या मैं इस वाक्य रचना में गलत कर रहा हूँ?

उत्तर

9

यदि आप उस पर टिप्पणी करने के लिए है:

let body : [String:Any] = ["id": userID, "name": userName, "contactInfo": contactInfo, "message": message] 
2

आपको चर के लिए [String: Any] स्पष्ट प्रकार जोड़ना चाहिए। प्रकार पता नहीं लगाया जा सकता है

let body = ["id": userID, 
      "name": userName, 
      "contactInfo": contactInfo, 
      "message": message] as [String: Any] 
संबंधित मुद्दे

 संबंधित मुद्दे