本文介绍了NSStringFromClass和isKindofClass on NSDistantObject类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数组 NSDistantObject 类对象。

NSLog(@"%@", [[saveClassObject objectAtIndex:0] connectionForProxy]);
        NSLog(@"%@", NSStringFromClass([[saveClassObject objectAtIndex:0] class]));
        if ([[saveClassObject objectAtIndex:0] isKindOfClass:[NSDistantObject class]]) {
            NSLog(@"Yes");
        }
        else {
            NSLog(@"NO");
        }

obove代码的输出是

Output for obove code is

2011-10-20 20:49:58.841 DistributedServer[4239:a0f] (** NSConnection 0x10013ec80 receivePort <CFSocket 0x1001133d0 [0x7fff70289ee0]>{valid = Yes, type = 1, socket = 3, socket set count = 140733193388036,
    callback types = 0x2, callout = __NSFireSocketAccept (0x7fff8254e74a), source = 0x10010abb0,
    run loops = <CFArray 0x10015f930 [0x7fff70289ee0]>{type = mutable-small, count = 4, values = (
    0 : <0x100112870>
    1 : <0x100112870>
    2 : <0x1001126a0>
    3 : <0x1001126a0>
)},
    context = <CFSocket context 0x1002000b0>} sendPort <02010610 1002c323 c0a801ae 00000000 00000000> refCount 3 **)
2011-10-20 20:49:58.842 DistributedServer[4239:a0f] NSDistantObject
2011-10-20 20:49:58.844 DistributedServer[4239:a0f] NO

NSStringFromClass 返回saveClassObject数组包含 NSDistantObject 类对象。 isKindofClass 返回否。为什么?

NSStringFromClass returns saveClassObject array contains NSDistantObject class object. isKindofClass returns No for the same. why?

推荐答案

NSProxy isKindOfClass:调用 forwardInvocation:。它试图测试代理所代表的对象的类,而不是代理本身。

NSProxy's -isKindOfClass: calls forwardInvocation:. It's intended to test the class of the object the proxy stands in for, not the proxy itself.


  • 要检查你所拥有的对象是否为代理,您可能需要使用。

  • To check if the object you have is a proxy, you might want to use isProxy instead.
  • To check the proxy's class, you could check if it's class equals [NSDistantObject class] or call isSubclassOfClass:.

这篇关于NSStringFromClass和isKindofClass on NSDistantObject类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:10