如何用 objective C class 做 IS?

How to do IS with an objective C class?

我尝试在 delphi Rio 10.3.3

下转换此 ios/objective-c 函数
func authorizationController(authorization: ASAuthorization) {
    if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { 

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

    }
}

我将 authorization.credential 设置为 pointer。现在我的问题是如何使用这个指针在投射之前检查 IS ASAuthorizationAppleIDCredential 例如:

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

您将使用 NSobject 中的 isKindOfClass: 选择器。你的情况

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

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

编辑:如果您只想对对象执行一个选择器,您还可以检查它是否使用 respondsToSelector 执行该选择器:https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418583-respondstoselector?language=objc