gpt4 book ai didi

objective-c - Objective C 中的安全转换

转载 作者:太空狗 更新时间:2023-10-30 03:32:38 25 4
gpt4 key购买 nike

在 Objective-C 中是否有类似 C++ 的安全转换?

我知道它们在 Objective C++ 中,但我不确定可能的副作用。使用 Objective C++ 可能会减慢编译时间 - 还有其他不使用它的原因吗?

最佳答案

Objective-c 确实有 C++ 安全转换。或者,我们可以使用运行时反射:

id myOb=[someObject getObject];
NSAssert([myOb isKindOfClass:[MyClass class]], @"Return value is not of type MyClass as expected.");
MyClass * newOb= (MyClass *)myOb;

引用资料:

Cocoa with Love :

关于objective-c - Objective C 中的安全转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2189850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com