任何人都可以帮助找到如何在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
但这不合适,我无法为对象分配任何值。帮助我弄清楚如何在swift中表示符合协议的对象
答案 0 :(得分:3)
也许你可以这样做:
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
}