Convert Unmanaged<AnyObject>! to Bool in Swift

It's been a long time since this has remained unanswered so I'm adding what I have learned along the way.

To convert a BOOL value returned by an Objective C method you can simply cast it using,

if let result = controlDelegate.performSelector("methodThatReturnsBOOL") {
    print("true")
} else {
    print("false")
}

Here you can also assign the value true/false to a Swift Bool, if required.

Note : I tried casting Unmanaged<AnyObject> directly to Bool using takeRetainedValue() as suggested by many answers on SO, but that doesn't seem to work in this scenario.

Tags:

Ios

Swift