Note that there are some explanatory texts on larger screens.

plurals
  1. POBreaking circular references while maintaining access to attributes (Objective-c)
    primarykey
    data
    text
    <p>I have two classes (<code>Test1</code> and <code>Test2</code>) that each have a property (<code>test2</code> and <code>test1</code> respectively) pointing to an instance of the other class. This means that <code>Test1.m</code> must import <code>Test2.h</code> and <code>Test2.m</code> must import <code>Test1.h</code>. The .h files must also have a forward declaration. Unfortunately, this means that I cannot access the attributes of <code>test2</code> and <code>test1</code> with dot notation. I can access them with message passing, but I should be able to use either notation. How can I resolve this problem?</p> <p><strong>Related</strong></p> <ul> <li><a href="https://stackoverflow.com/questions/2175168/strange-behaviour-for-view-property-of-view-controller">Strange behavior for view property of view controller</a></li> </ul> <p><strong>Test1</strong></p> <pre><code>//Test1.h @class Test2; @interface Test1 : NSObject { Test2* test2; int a1; } @property (nonatomic, retain) Test2* test2; - (void)meth1; @end //Test1.m #import "Test1.h" #import "Test2.h" @implementation Test1 @synthesize test2; - (void)meth1{ test2.a2;//Request for member 'a2' in something not a structure or union } @end </code></pre> <p><strong>Test2</strong></p> <pre><code>//Test2.h #import &lt;Foundation/Foundation.h&gt; @class Test1; @interface Test2 : NSObject { Test1 *test1; int a2; } @property (nonatomic, assign) Test1* test1; - (void)meth2; @end //Test2.m #import "Test2.h" #import "Test1.h" @implementation Test2 @synthesize test1; - (void)meth2{ test1.a1;//Request for member 'a1' in something not a structure or union } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload