2016-03-07 107 views
0

我试图将一些参数传递给我的解析云代码函数,并在Xcode中收到以下错误消息。 cannot convert value of type '[String : String?]' to type '[NSObject : AnyObject]' in coercion。它工作正常,直到我参考incomingUser.objectId。以下是我所传递的代码:键入objectId来解析云代码

let params = ["userType" : userType, "recipient" : self.incomingUser.objectId] 

PFCloud.callFunctionInBackground("pushNotification", withParameters: params as [NSObject : AnyObject]) { 
    (res: AnyObject?, error: NSError?) -> Void in 
     print(res) 
     print(error) 
} 

感谢您提供任何帮助。

回答

1

尝试使用params as [NSObject: AnyObject?]代替。

或者如果API要求[NSObject: AnyObject],则必须首先打开objectId

guard let objectId = self.incomingUser.objectId else { return } 

然后做

let params = ["userType" : userType, "recipient" : objectId] 

PFCloud.callFunctionInBackground("pushNotification", withParameters: params as [NSObject : AnyObject]) { 
(res: AnyObject?, error: NSError?) -> Void in 
    print(res) 
    print(error) 
} 
+0

警卫工作声明此。你介意解释为什么需要“展开”?非常感谢你的帮助! – Robert

+0

我会推荐[this](http://stackoverflow.com/questions/24034483/what-is-an-unwrapped-value-in-swift)供参考。我不擅长用英语解释事情:P。但是,在阅读完上述答案之后,请告诉我您是否有其他难题。 –

+0

会做,再次感谢! – Robert