The object conforms to the Swift protocol.

Can anyone help find how to write this in Swift

NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];

The above ObjectiveC code says that the objecttype NSMutableDictionaryconforms to the protocol FBOpenGraphObject. I tried to imagine it quickly as

var object:FBOpenGraphObject, Dictionary = FBGraphObject.openGraphActionForPost()

// specify that this Open Graph object will be posted to Facebook
object.provisionedForPost = true   //This will not work

But this is not correct, I cannot assign any value to the object. Help me understand how to represent an object according to the protocol in a quick

+4
source share
1 answer

Perhaps you could do this:

var obj = FBGraphObject.openGraphActionForPost()
if let fbObj = obj as? FBOpenGraphObject {
    // specify that this Open Graph object will be posted to Facebook
    fbObj.provisionedForPost = true // use fbObj for FBOpenGraphObject-specific members
    obj["title"] = "Test hot spot" // use obj for Dictionary-specific members
    // Both obj and fbObj vars point to the same object
}
+3
source

All Articles