谁能帮忙找到如何用Swift
编写此代码
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
上面的ObjectiveC代码表示
object
类型的NSMutableDictionary
符合协议FBOpenGraphObject
。我试图迅速地代表这个var object:FBOpenGraphObject, Dictionary = FBGraphObject.openGraphActionForPost()
// specify that this Open Graph object will be posted to Facebook
object.provisionedForPost = true //This will not work
但这是不合适的,我无法为对象分配任何值。帮我弄清楚如何快速地表示对象符合协议
最佳答案
也许您可以这样做:
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
}