Search code examples
iosswiftxcodedelphifiremonkey

How to do IS with an objective C class?


I try to convert this ios/objective-c function under delphi Rio 10.3.3

func authorizationController(authorization: ASAuthorization) {
    if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { 

    } else if let passwordCredential = authorization.credential as? ASPasswordCredential {

    }
}

I set authorization.credential to be a pointer. Now my problem how with this pointer can I check the IS ASAuthorizationAppleIDCredential before to cast like for example :

if authorization.credential IS ASAuthorizationAppleIDCredential then 
  TASAuthorizationAppleIDCredential.wrap(authorization.credential);

Solution

  • You would use the isKindOfClass: selector that is in NSobject. In your case

    if([authorization.credential isKindOfClass:[AsAuthorizationAppleIDCredential class]])
    { // is that class }
    

    https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418511-iskindofclass?language=objc

    EDIT: If you want to only perform one selector on the object you could also check if it performs that selector with respondsToSelector: https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418583-respondstoselector?language=objc