ios - 如何用 objective-c 类做IS?

标签 ios swift xcode delphi firemonkey

我尝试在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

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

关于ios - 如何用 objective-c 类做IS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61312870/

相关文章:

objective-c - 使 AVAudioPCMBuffer 工作(AVAudioFile.mm 错误代码 -50)

ios - 在 SwiftUI 中对齐包含的 View

iphone - 如何从 JSON 中获取的字典中获取信息 - Objective-C/IOS/xCode

我的二进制忽略设置的 iOS 最低操作系统要求

swift - xcode:没有这样的模块 'Kingfisher'

ios - 是否可以从 HealthKit 读取 Apple Watch 目标(移动、走步和站立)?

ios - Swift 3 - 排序数组/字典 : '(AnyObject)' is not a subtype of 'NSString'

ios - 如何在 ios 应用程序中合并两个半图像?

ios - swift 3,ios 10 - 未收到推送通知 firebase

ios - 在objective-c中导入swift类,<myModule>-Swift.h文件未找到