Reputation: 1261
I am building an iOS app which requires sharing on Facebook. I am using Swift(4) on Xcode(9). So I started using the documentation from the official page of Facebook -> Facebook Swift SDK
However, to my surprise almost every example listed in this page and others are giving compilation errors. For e.g. on this page there is a suggested way for LinkShareContent
as per below:
import FacebookShare
let content = LinkShareContent(url: NSURL("https://developers.facebook.com"))
try ShareDialog.show(from: myViewController, content: content)
But the minute I add this to my code, I get the error -> Argument labels '(_:)' do not match any available overloads
on the NSURL
So it seems like the documentation for Facebook SDK for Swift is outdated. Am I correct? if yes, can someone please guide me to the most updated version? Or what are my other options? If someone can at least tell me which version the current documentation corresponds to, then at least I can start working on an older version of the SDK.
Upvotes: 1
Views: 312
Reputation: 9362
The SDK has been updated for Swift 4, but apparently not the documentation. The correct Swift 4 syntax for creating NSURL
from a string requires a string
argument label:
let url = NSURL(string: "https://developers.facebook.com")
You are looking at Facebook's official documentation, so I don't know where to point you to anything more up-to-date. It might help to re-type their example code into your project so you can get the right auto-completion suggestions from Xcode.
EDIT: In Swift, many classes with the NS
prefix have been replaced by classes without the prefix. For example, NSURL
has been replaced in favor of URL
. Facebook has updated their LinkShareContent
class to take a URL
in the initializer:
public init(url: URL, quote: String? = nil)
So this should work:
let content = LinkShareContent(url: URL(string: "https://developers.facebook.com"))
P.S. Again, this is the reason you should re-type their example code instead of copy/pasting. As soon as you type let content = LinkShareContent(
, Xcode will you show you that the initializer needs a URL
not NSURL
.
Upvotes: 2