我想知道我们如何在 Swift 中做到这一点?
我正在尝试将下面的代码转换为 Swift
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
// handle successful response
} else if ([[error userInfo][@"error"][@"type"] isEqualToString: @"OAuthException"]) { // Since the request failed, we can
NSLog(@"The facebook session error");
} else {
NSLog(@"Some other error: %@", error);
}
}];
这是我所做的。
request.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if error == nil {
// handle successful response
}
else if error.userInfo["error"]["type"] == "OAuthException" {
//THIS LINE WONT COMPILE
}
else {
println("Some other error");
}
}
但是我得到一个编译错误,could not find member 'subscript'
在这一行上说
error.userInfo["error"]["type"] == "OAuthException"
请问有什么想法吗?