在objC中还真有一个类方法class,可以得到当前实例变量的类型。
define:
+(Class)class;
example:
UIViewController *vc=[[UIViewController alloc] init];
NSLog(@"vc type is :%@",[vc class]);

解决方案 »

  1.   

    这样的话就必须实例化,,那假如我在头文件中写@property(nonation,strong)NSString *str,,,然后在.m文件中直接用【str class】是没法得到的,而我又不想实例化,,有没有其他办法呢?
      

  2.   

    +(Class)class;是静态方法,不用实例化。
    比如直接[UIViewController class]就行了。
      

  3.   

    @property(nonatomic,strong)Class1 a; 
    @property(nonatomic,strong)Class2 b;
     @property(nonatomic,strong)Class3 c; -(void)inject:(argc...)

          [defaultFactory componentForType:参数的类名];
     } 
    argc...:传进来的参数是不定个数的, 
    然后在函数中需要知道变量是那个类的。 
    问题:如果用object_getClassName 或者 (Class)class 的话,因为类变量a、b、c 没alloc,所以得到的是空,,有没有其他的解决办法呢??