【发布时间】:2015-04-13 05:15:16
【问题描述】:
[原始问题] 如何在 Swift 1.2 中使用 NSString 将字符串传递给方法
我遇到了 String 和 NSString 的问题。使用 Facebook SDK 我正在使用:
FBRequestConnection.startWithGraphPath("/me/feed", parameters: params, HTTPMethod: NSString(string:"POST"), completionHandler:{(connection:FBRequestConnection!, result:AnyObject!, error:NSError?) -> Void in .... my code here ...})
1.2之前还可以,现在不知道怎么办了,用HTTPMethod试过了:
HTTPMethod: NSString(string:"POST") as! /*(and also as? and as)*/ String
但似乎没有任何效果。我也用过HTTPMethod: "POST",但也是个问题(因为函数需要NSString)
"'NSString' 不能隐式转换为 'String';您的意思是使用 'as' 显式转换吗?" 是错误。
还有: 不能使用类型为“(字符串,参数:NSDictionary!,HTTPMethod:字符串,completionHandler:FBRequestHandler)”的参数列表调用“startWithGraphPath” (如果我只使用字符串)
如何避免这个问题?
[更新] 看来问题出在参数上:
我有:
params = NSDictionary(dictionary: [
"contentTitle" : _nameTxt.string,
"caption" : _captionTxt.string,
"contentDescription" : _descriptionTxt.string,
"contentURL" : "http://somelink.com/index.php",
"imageURL" : "http://somelink.com/media/image.png"
])
当我尝试时: 参数:nil,应用程序编译 但是使用参数:params,我得到一个错误
【问题讨论】:
标签: ios string facebook swift nsstring