【问题标题】:I have to convert objective c code into swift3.0, I'm getting errors while trying online conversion我必须将目标 c 代码转换为 swift 3.0,尝试在线转换时出错
【发布时间】:2017-03-15 11:59:26
【问题描述】:
NSURL *contentURL = [[NSURL alloc] initWithString: @"http://en.wikipedia.org/wiki/Facebook"];

NSURL *imageURL = [NSURL URLWithString:@"http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg"];

button.shareContent = [[FBSDKShareLinkContent alloc]
                        initWithContentURL: contentURL
                              contentTitle: @"My Share Title"
                        contentDescription: @"Lorem ipsum dolor sit amet."
                                  imageURL: imageURL
                                 peopleIDs: @[@"1561082740838259"]
                                   placeID: @"166793820034304"
                                       ref: @"myRefId"];

【问题讨论】:

  • 您遇到什么错误?您需要为您的问题提供更多详细信息。
  • 无法使用类型为 '(contentURL: URL?, contentTitle: String, contentDescription: String, imageURL: URL?, peopleIDs: [String], placeID:字符串,参考:字符串)

标签: swift3 fbsdk fbsdksharekit


【解决方案1】:

在线转换没有问题(编译器只抱怨我没有定义 FBSDKShareLinkContent:

func dummy(button: UIButton) {
    //  Converted with Swiftify v1.0.6276 - https://objectivec2swift.com/
    var contentURL = URL(string: "http://en.wikipedia.org/wiki/Facebook")
    var imageURL = URL(string: "http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg")
    button.shareContent = FBSDKShareLinkContent(contentURL: contentURL, contentTitle: "My Share Title", contentDescription: "Lorem ipsum dolor sit amet.", imageURL: imageURL, peopleIDs: ["1561082740838259"], placeID: "166793820034304", ref: "myRefId")

}

我在评论中包含了一个在线转换器的链接(实际上我只是把它留在里面,转换器添加了它!)

【讨论】:

  • 我收到此错误......无法使用类型为“(contentURL:URL?,contentTitle)的参数列表调用类型“FBSDKShareLinkContent”的初始化程序: String, contentDescription: String, imageURL: URL?, peopleIDs: [String], placeID: String, ref: String)'
  • 您正在向我展示您发送到 FBSDKShareLinkContent 的内容,但您没有告诉我它对参数的期望。如果不是您的代码,请 CMD 单击 FBSDKShareLinkContent 并将 FBSDKShareLinkContent 的标头定义复制并粘贴到您上面的问题中。您的参数(包括它们的类型)必须与预期的参数完全匹配。它可能就像添加一些 NSURL 的变体一样简单,或者您可能在其他地方有不匹配的类型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-14
  • 1970-01-01
相关资源
最近更新 更多