You can call any class methods to AnyClass
// ↓
var networks: Dictionary<String, AnyClass> = [
"facebook": PFFacebookUtils.self,
"twitter": PFTwitterUtils.self
];
var flag = networks[network]?.isLinkedWithUser(user)
if flag == nil {
// no such network
}
else if flag! {
// linked
}
else {
// not linked
}
If you don't know what ?
means, see this document.
If you are sure networks[network]
is exists:
var flag = networks[network]!.isLinkedWithUser(user)
if flag {
// linked
}
else {
// not linked
}
ADDED:
About unlinkUserInbackground
method.
At first, I don't know the exact reason why the compiler cannot find this method, maybe a bug or maybe not. Following is a workaround I found.
unlinkUserInbackground
method has 3 variations
class func unlinkUserInBackground(user: PFUser!) -> BFTask!
class func unlinkUserInBackground(user: PFUser!, block: PFBooleanResultBlock!)
class func unlinkUserInBackground(user: PFUser!, target: AnyObject!, selector: Selector)
I think, it's conflicted with each other.
If you import Bolts
framework in YourProduct-Bridging-Header.h
like this:
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <Bolts/Bolts.h>
then, you can call the first one.
let cls:AnyClass = networks[network]!
let task = cls.unlinkUserInBackground(user)
For the last 2, the workaround I found is... declaring an protocol like this.
@objc protocol SNSUtils {
class func unlinkUserInBackground(user: PFUser!, block: PFBooleanResultBlock!)
class func unlinkUserInBackground(user: PFUser!, target: AnyObject!, selector: Selector)
}
// ...
let cls:AnyClass = networks[network]!
cls.unlinkUserInBackground(user, block: { (success, err) -> Void in
println("sucess: \(success) err: \(err)")
})
I know, it's odd, but it's actually working in my environment.