unknown type name in objective c

前端 未结 6 1639
生来不讨喜
生来不讨喜 2021-01-03 22:55

I\'m pretty new to objective c, and having some basic problems.

I wrote a simple program using a navigator, and everything worked fine. then I added few lines of cod

6条回答
  •  轮回少年
    2021-01-03 23:41

    As others have mentioned, this is indeed caused by cyclic imports. To fix this remove the imports in one of the classes. But sometimes this is not sufficient. If the classes depend on each other, simply forward-declare the one class in the other:

    Class A:

    #import 
    @class B; //<- this is essential here
    
    @interface A: NSObject
    
    @property(nonatomic, strong) B *b;
    //...
    

    In class B we have:

    #import "A.h"
    @interface B: NSObject
    
    @property(nonatomic, strong) A *a;
    

提交回复
热议问题