【问题标题】:FBRequestConnection method in Swift 1.2Swift 1.2 中的 FBRequestConnection 方法
【发布时间】: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


    【解决方案1】:

    我相信你可以只做 HTTPMethod = "POST"

    【讨论】:

    • 不。 “无法使用类型为'(String,参数:NSDictionary!,HTTPMethod:String,completionHandler:FBRequestHandler)'的参数列表调用'startWithGraphPath'”是这种情况下的问题
    • 好的,问题不是字符串而是参数。我已经编辑了问题
    【解决方案2】:

    好的,在尝试使用“parameters: nil”并编译应用程序后,我发现问题不仅在于 NSString,还在于 NSDictionary。现在(我认为更好)我应该使用所有 Swift 原生代码。

    所以: “me/feed”和“POST”必须是字符串参数:参数必须是字典

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      相关资源
      最近更新 更多